Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Select): replace defaultProps property #1146

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/components/forms/Select/CreatableSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cls from 'classnames';
import { Strong } from '../../Text';
import { TextVariants } from '../../Text/Text.enums';
import { useSelectProps } from './useSelectProps';
import Select from './Select';
import { CreatableSelectProps } from './Select.types';
import { CLX_COMPONENT } from '../../../theme/constants';

Expand All @@ -20,9 +19,25 @@ const renderCreateLabel = (createNewLabel: string) => (inputValue: string) =>
function CreatableSelect<IsMulti extends boolean = false>({
createNewLabel = 'Create',
isAsync = false,
placeholder = '',
isInvalid = false,
isDisabled = false,
isClearable = false,
maxPillLabelLength = 16,
isMenuPositionRelative = false,
className = '',
...props
}: CreatableSelectProps<IsMulti>): React.ReactElement {
const selectProps = useSelectProps<IsMulti>(props);
const selectProps = useSelectProps<IsMulti>({
placeholder,
isInvalid,
isDisabled,
isClearable,
maxPillLabelLength,
isMenuPositionRelative,
className,
...props,
});

if (isAsync) {
return (
Expand All @@ -43,8 +58,6 @@ function CreatableSelect<IsMulti extends boolean = false>({
);
}

CreatableSelect.defaultProps = Select.defaultProps;

CreatableSelect.displayName = 'CreatableSelect';

export default CreatableSelect;
29 changes: 17 additions & 12 deletions src/components/forms/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@ import { CLX_COMPONENT } from '../../../theme/constants';

function Select<IsMulti extends boolean = false>({
isAsync = false,
placeholder = '',
isInvalid = false,
isDisabled = false,
isClearable = false,
maxPillLabelLength = 16,
isMenuPositionRelative = false,
className = '',
...props
}: SelectProps<IsMulti>): React.ReactElement {
const selectProps = useSelectProps<IsMulti>(props);
const { className } = props;
const selectProps = useSelectProps<IsMulti>({
placeholder,
isInvalid,
isDisabled,
isClearable,
maxPillLabelLength,
isMenuPositionRelative,
className,
...props,
});

if (isAsync) {
return (
Expand All @@ -28,16 +43,6 @@ function Select<IsMulti extends boolean = false>({
);
}

Select.defaultProps = {
placeholder: '',
isInvalid: false,
isDisabled: false,
isClearable: false,
maxPillLabelLength: 16,
isMenuPositionRelative: false,
className: '',
};

Select.displayName = 'Select';

export default Select;
Loading