-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ValidCreatableSelect): separate CreatableSelect from Select #patch
- Loading branch information
Showing
16 changed files
with
186 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/// <reference types="react" /> | ||
import { ValidSelectProps } from ".."; | ||
export declare const ValidCreatableSelect: ({ label, placeholder, options, name, value, onChange, errMessage, optionalLabel, isInvalid, isDisabled, isRequired, isClearable, tooltip, selectDataQa, isMulti, className, helperText, ...props }: ValidSelectProps) => JSX.Element; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
build/components/styled-atlaskit/CreatableSelect/CreatableSelect.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// <reference types="react" /> | ||
import "../Select/Select.scss"; | ||
import { SelectProps } from "../Select/Select"; | ||
export declare const CreatableSelect: ({ isMulti, onChange, ...props }: SelectProps) => JSX.Element; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/components/ValidatedInput/ValidCreatableSelect.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2022 AccelByte Inc. All Rights Reserved. | ||
* This is licensed software from AccelByte Inc, for limitations | ||
* and restrictions contact your company contract manager. | ||
*/ | ||
|
||
import React from "react"; | ||
import { Meta, Story } from "@storybook/react/types-6-0"; | ||
import { ValidSelectProps } from "./ValidSelect"; | ||
import { ValidCreatableSelect } from "./ValidCreatableSelect"; | ||
import { SelectOption } from "../../types"; | ||
|
||
export default { | ||
title: "Components/ValidatedInput/ValidCreatableSelect", | ||
component: ValidCreatableSelect, | ||
} as Meta; | ||
|
||
const Template: Story<ValidSelectProps> = (args) => { | ||
const [option, setOption] = React.useState<SelectOption | null>(null); | ||
const onChange = (option: SelectOption) => { | ||
setOption(option); | ||
}; | ||
return <ValidCreatableSelect {...args} value={option} onChange={onChange} />; | ||
}; | ||
|
||
export const Example = Template.bind({}); | ||
Example.args = { | ||
options: [ | ||
{ label: "Value 1", value: "value1" }, | ||
{ label: "Value 2", value: "value2" }, | ||
], | ||
label: "Label", | ||
placeholder: "Select please...", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* * Copyright (c) 2022 AccelByte Inc. All Rights Reserved. | ||
* * This is licensed software from AccelByte Inc, for limitations | ||
* * and restrictions contact your company contract manager. | ||
* | ||
*/ | ||
|
||
import * as React from "react"; | ||
import { default as classNames } from "classnames"; | ||
import { FieldErrorMessage, FieldHelperText, FieldLabel } from "../Form/utility"; | ||
import { CreatableSelect, ValidSelectProps } from ".."; | ||
|
||
export const ValidCreatableSelect = ({ | ||
label, | ||
placeholder, | ||
options = [], | ||
name, | ||
value, | ||
onChange, | ||
errMessage, | ||
optionalLabel, | ||
isInvalid, | ||
isDisabled = false, | ||
isRequired = true, | ||
isClearable, | ||
tooltip, | ||
selectDataQa, | ||
isMulti = false, | ||
className, | ||
helperText, | ||
...props | ||
}: ValidSelectProps) => ( | ||
<div className={classNames("valid-select-input", className)}> | ||
{!!label && <FieldLabel label={label} optionalLabel={optionalLabel} isRequired={isRequired} tooltip={tooltip} />} | ||
<CreatableSelect | ||
{...props} | ||
options={options} | ||
placeholder={placeholder} | ||
name={name} | ||
value={value} | ||
onChange={onChange} | ||
isDisabled={isDisabled} | ||
isClearable={isClearable} | ||
isMulti={isMulti} | ||
dataQa={selectDataQa} | ||
/> | ||
{isInvalid && <FieldErrorMessage message={errMessage} />} | ||
{helperText && <FieldHelperText message={helperText} />} | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/components/styled-atlaskit/CreatableSelect/CreatableSelect.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2022 AccelByte Inc. All Rights Reserved. | ||
* This is licensed software from AccelByte Inc, for limitations | ||
* and restrictions contact your company contract manager. | ||
*/ | ||
|
||
import React from "react"; | ||
import { Meta, Story } from "@storybook/react/types-6-0"; | ||
import { CreatableSelect } from "./CreatableSelect"; | ||
import { SelectOption } from "../../../types"; | ||
import { SelectProps } from "../Select/Select"; | ||
|
||
export default { | ||
title: "Components/CreatableSelect", | ||
component: CreatableSelect, | ||
} as Meta; | ||
|
||
const Template: Story<SelectProps> = (args) => { | ||
const [option, setOption] = React.useState<SelectOption>(args.value); | ||
const onChange = (option: SelectOption) => { | ||
setOption(option); | ||
}; | ||
|
||
React.useEffect(() => { | ||
setOption(args.value); | ||
}, [args.value]); | ||
return <CreatableSelect {...args} value={option} onChange={onChange} />; | ||
}; | ||
|
||
export const Example = Template.bind({}); | ||
Example.args = { | ||
value: { label: "Value 1", value: "value1" }, | ||
options: [ | ||
{ label: "Value 1", value: "value1" }, | ||
{ label: "Value 2", value: "value2" }, | ||
{ label: "Value 3", value: "value3" }, | ||
{ label: "Value 4", value: "value4" }, | ||
{ label: "Value 5", value: "value5" }, | ||
{ label: "Value 6", value: "value6" }, | ||
{ label: "Value 7", value: "value7" }, | ||
{ label: "Value 8", value: "value8" }, | ||
{ label: "Value 9", value: "value9" }, | ||
], | ||
}; |
23 changes: 23 additions & 0 deletions
23
src/components/styled-atlaskit/CreatableSelect/CreatableSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 202s AccelByte Inc. All Rights Reserved. | ||
* This is licensed software from AccelByte Inc, for limitations | ||
* and restrictions contact your company contract manager. | ||
*/ | ||
|
||
import React from "react"; | ||
import { CreatableSelect as AkCreatableSelect } from "@atlaskit/select"; | ||
import { SelectOption } from "../../../types"; | ||
import "../Select/Select.scss"; | ||
import { SelectProps } from "../Select/Select"; | ||
|
||
export const CreatableSelect = ({ isMulti = false, onChange, ...props }: SelectProps) => { | ||
return ( | ||
<AkCreatableSelect | ||
className="styled-atlaskit-select" | ||
classNamePrefix={"styled-atlaskit-select"} | ||
isMulti={isMulti} | ||
onChange={onChange ? (item) => onChange(item as SelectOption) : undefined} | ||
{...props} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters