-
Notifications
You must be signed in to change notification settings - Fork 21
Implement generic multiselect input & skill select input #697
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
37 changes: 37 additions & 0 deletions
37
src/libs/shared/lib/components/input-skill-selector/InputSkillSelector.tsx
This file contains hidden or 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,37 @@ | ||
| import { ChangeEvent, FC } from 'react' | ||
| import { noop } from 'lodash' | ||
|
|
||
| import { InputMultiselect } from '~/libs/ui' | ||
|
|
||
| import { autoCompleteSkills } from '../../services/emsi-skills' | ||
|
|
||
| interface Option { | ||
| label: string | ||
| value: string | ||
| } | ||
|
|
||
| const fetchSkills = (queryTerm: string): Promise<Option[]> => ( | ||
| autoCompleteSkills(queryTerm) | ||
| .then(skills => ( | ||
| skills.map(skill => ({ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we here filter out the already selected skills so they do not appear in the results? |
||
| label: skill.name, | ||
| value: skill.emsiId, | ||
| })) | ||
| )) | ||
| ) | ||
|
|
||
| interface InputSkillSelectorProps { | ||
| readonly onChange?: (event: ChangeEvent<HTMLInputElement>) => void | ||
| } | ||
|
|
||
| const InputSkillSelector: FC<InputSkillSelectorProps> = props => ( | ||
| <InputMultiselect | ||
| label='Select Skills' | ||
| placeholder='Type to add a skill...' | ||
| onFetchOptions={fetchSkills} | ||
| name='skills' | ||
| onChange={props.onChange ?? noop} | ||
| /> | ||
| ) | ||
|
|
||
| export default InputSkillSelector | ||
This file contains hidden or 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 @@ | ||
| export { default as InputSkillSelector } from './InputSkillSelector' |
8 changes: 8 additions & 0 deletions
8
src/libs/shared/lib/services/emsi-skills/emsi-skills.service.ts
This file contains hidden or 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,8 @@ | ||
| import { EnvironmentConfig } from '~/config' | ||
| import { xhrGetAsync } from '~/libs/core' | ||
|
|
||
| import Skill from './skill.model' | ||
|
|
||
| export async function autoCompleteSkills(queryTerm: string): Promise<Skill[]> { | ||
| return xhrGetAsync(`${EnvironmentConfig.API.V5}/emsi-skills/skills/auto-complete?term=${queryTerm}`) | ||
| } |
This file contains hidden or 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,2 @@ | ||
| export * from './skill.model' | ||
| export * from './emsi-skills.service' |
This file contains hidden or 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 @@ | ||
| export default interface Skill { | ||
| name: string; | ||
| emsiId: string; | ||
| } |
This file contains hidden or 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
146 changes: 146 additions & 0 deletions
146
...lib/components/form/form-groups/form-input/input-multiselect/InputMultiselect.module.scss
This file contains hidden or 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,146 @@ | ||
| @import '../../../../../styles/includes'; | ||
|
|
||
| .multiselect .ms { | ||
| display: block; | ||
|
|
||
| &:global(__value-container) { | ||
| display: flex; | ||
| align-items: center; | ||
| flex: 1; | ||
| flex-wrap: wrap; | ||
| position: relative; | ||
| overflow: hidden; | ||
| margin: 0 10px; | ||
| padding: 0; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| &:global(__indicators) { | ||
| display: none; | ||
| } | ||
|
|
||
| &:global(__placeholder) { | ||
| position: absolute; | ||
| font-size: 14px; | ||
| line-height: 16px; | ||
| color: $black-60; | ||
| } | ||
|
|
||
| &:global(__control) { | ||
| border: 0 none; | ||
| box-shadow: none; | ||
|
|
||
| align-items: center; | ||
| cursor: default; | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| justify-content: space-between; | ||
| min-height: 0; | ||
| outline: 0!important; | ||
| position: relative; | ||
| transition: all 100ms; | ||
| background: none; | ||
| border-radius: 4px; | ||
| } | ||
|
|
||
| &:global(__input-container) { | ||
| font-size: 14px; | ||
| line-height: 16px; | ||
| color: $black-60; | ||
| display: inline-grid; | ||
| flex: 1 1 auto; | ||
| margin: 0; | ||
| grid-template-columns: 0 min-content; | ||
| padding: 0; | ||
| visibility: visible; | ||
| } | ||
|
|
||
| &:global(__multi-value) { | ||
| margin: 0; | ||
| background: $teal-140; | ||
| color: $tc-white; | ||
| border-radius: 4px; | ||
|
|
||
| &:global(__remove) { | ||
| cursor: pointer; | ||
| border: 0 none; | ||
| background: none; | ||
| outline: none; | ||
| appearance: none; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| border-radius: 4px; | ||
| padding: 2px; | ||
| margin: 2px 6px 2px 0; | ||
|
|
||
| svg { | ||
| display: block; | ||
| width: 16px; | ||
| height: 16px; | ||
| } | ||
| } | ||
| &:global(__label) { | ||
| color: $tc-white; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| border-radius: 4px; | ||
| padding: 4px; | ||
| padding-left: 8px; | ||
| padding-right: 2px; | ||
| font-size: 14px; | ||
| line-height: 16px; | ||
| letter-spacing: 0.5px; | ||
| font-family: $font-roboto; | ||
| font-weight: $font-weight-medium; | ||
| } | ||
| } | ||
|
|
||
| &:global(__menu) { | ||
| top: 100%; | ||
| position: absolute; | ||
| width: 100%; | ||
| z-index: 1; | ||
| background-color: $tc-white; | ||
| border-radius: 4px; | ||
| box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.25); | ||
| margin-bottom: 5px; | ||
| margin-top: 5px; | ||
| border: 1px solid $black-40; | ||
| &:global(-list) { | ||
| max-height: 300px; | ||
| overflow-y: auto; | ||
| position: relative; | ||
| -webkit-overflow-scrolling: touch; | ||
| padding: 8px 0; | ||
| } | ||
| &:global(-notice) { | ||
| text-align: center; | ||
| color: #999; | ||
| padding: 8px 12px; | ||
| } | ||
| } | ||
| &:global(__option) { | ||
| cursor: default; | ||
| display: block; | ||
| width: 100%; | ||
| user-select: none; | ||
| -webkit-tap-highlight-color: rgba(0, 0, 0, 0); | ||
| background-color: transparent; | ||
| color: $black-100; | ||
| padding: 8px 16px; | ||
|
|
||
| font-size: 16px; | ||
| line-height: 24px; | ||
|
|
||
| &:global(--is-focused) { | ||
| background-color: $turq-160; | ||
| color: $tc-white; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .multiselect { | ||
| margin: 8px -10px 0; | ||
| } |
45 changes: 45 additions & 0 deletions
45
...lib/components/form/form-groups/form-input/input-multiselect/InputMultiselect.stories.tsx
This file contains hidden or 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,45 @@ | ||
| /* eslint-disable no-underscore-dangle */ | ||
| /* eslint-disable camelcase */ | ||
| import { Meta, StoryObj } from '@storybook/react' | ||
|
|
||
| import { InputMultiselect } from '.' | ||
|
|
||
| const meta: Meta<typeof InputMultiselect> = { | ||
| argTypes: { | ||
| }, | ||
| component: InputMultiselect, | ||
| excludeStories: /.*Decorator$/, | ||
| // tags: ['autodocs'], | ||
| title: 'Forms/InputMultiselect', | ||
| } | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof InputMultiselect>; | ||
|
|
||
| export const Basic: Story = { | ||
| args: { | ||
| onChange: d => console.log(d), | ||
| onFetchOptions: d => Promise.resolve(d ? [ | ||
| { label: 'Option 1', value: '1' }, | ||
| { label: 'Option 2', value: '2' }, | ||
| { label: 'Option 3', value: '3' }, | ||
| { label: 'Option 4', value: '4' }, | ||
| { label: 'Option 5', value: '5' }, | ||
| { label: 'Option 6', value: '6' }, | ||
| { label: 'Option 7', value: '7' }, | ||
| { label: 'Option 8', value: '8' }, | ||
| { label: 'Option 9', value: '9' }, | ||
| { label: 'Option 10', value: '10' }, | ||
| { label: 'Option 11', value: '11' }, | ||
| { label: 'Option 12', value: '12' }, | ||
| { label: 'Option 13', value: '13' }, | ||
| { label: 'Option 14', value: '14' }, | ||
| { label: 'Option 15', value: '15' }, | ||
| { label: 'Option 16', value: '16' }, | ||
| { label: 'Option 17', value: '17' }, | ||
| { label: 'Option 18', value: '18' }, | ||
| { label: 'Option 19', value: '19' }, | ||
| ] : []), | ||
| }, | ||
| } |
82 changes: 82 additions & 0 deletions
82
...libs/ui/lib/components/form/form-groups/form-input/input-multiselect/InputMultiselect.tsx
This file contains hidden or 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,82 @@ | ||
| import { | ||
| ChangeEvent, | ||
| FC, | ||
| ReactNode, | ||
| } from 'react' | ||
| import { noop } from 'lodash' | ||
| import { components } from 'react-select' | ||
| import AsyncSelect from 'react-select/async' | ||
|
|
||
| import { InputWrapper } from '../input-wrapper' | ||
| import { IconSolid } from '../../../../svgs' | ||
|
|
||
| import styles from './InputMultiselect.module.scss' | ||
|
|
||
| export interface InputMultiselectOption { | ||
| label?: ReactNode | ||
| value: string | ||
| } | ||
|
|
||
| interface InputMultiselectProps { | ||
| readonly dirty?: boolean | ||
| readonly disabled?: boolean | ||
| readonly error?: string | ||
| readonly hideInlineErrors?: boolean | ||
| readonly hint?: string | ||
| readonly label?: string | ||
| readonly name: string | ||
| readonly onChange: (event: ChangeEvent<HTMLInputElement>) => void | ||
| readonly options?: ReadonlyArray<InputMultiselectOption> | ||
| readonly placeholder?: string | ||
| readonly tabIndex?: number | ||
| readonly value?: string | ||
| readonly onFetchOptions?: (query: string) => Promise<InputMultiselectOption[]> | ||
| } | ||
|
|
||
| const MultiValueRemove: FC = (props: any) => ( | ||
| <components.MultiValueRemove {...props}> | ||
| <IconSolid.XCircleIcon /> | ||
| </components.MultiValueRemove> | ||
| ) | ||
|
|
||
| const InputMultiselect: FC<InputMultiselectProps> = (props: InputMultiselectProps) => { | ||
|
|
||
| function handleOnChange(options: readonly InputMultiselectOption[]): void { | ||
| props.onChange({ | ||
| target: { value: options }, | ||
| } as unknown as ChangeEvent<HTMLInputElement>) | ||
| } | ||
|
|
||
| return ( | ||
| <InputWrapper | ||
| {...props} | ||
| dirty={!!props.dirty} | ||
| disabled={!!props.disabled} | ||
| label={(props.label || props.name) ?? 'Select Option'} | ||
| hideInlineErrors={props.hideInlineErrors} | ||
| type='text' | ||
| > | ||
| <AsyncSelect | ||
| className={styles.multiselect} | ||
| classNamePrefix={styles.ms} | ||
| unstyled | ||
| isMulti | ||
| cacheOptions | ||
| autoFocus | ||
| defaultOptions | ||
| placeholder={props.placeholder} | ||
| loadOptions={props.onFetchOptions} | ||
| name={props.name} | ||
| onChange={handleOnChange} | ||
| onBlur={noop} | ||
| blurInputOnSelect={false} | ||
| components={{ | ||
| // MultiValueLabel: () => | ||
| MultiValueRemove, | ||
| }} | ||
| /> | ||
| </InputWrapper> | ||
| ) | ||
| } | ||
|
|
||
| export default InputMultiselect |
2 changes: 2 additions & 0 deletions
2
src/libs/ui/lib/components/form/form-groups/form-input/input-multiselect/index.ts
This file contains hidden or 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,2 @@ | ||
| export { default as InputMultiselect } from './InputMultiselect' | ||
| export { type InputMultiselectOption } from './InputMultiselect' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss this...