-
Notifications
You must be signed in to change notification settings - Fork 21
TCA-441 implement sort filter on learn landing ->dev #298
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3594327
TCA-441 - implement form input select
vas3a efa1d12
TCA-441 - implement certificates sorting on tca landing page
vas3a 8a1922d
add storage hook to keep state in sync with local storage
vas3a fcacff3
lint fixes
vas3a 6b23142
TCA-441 - add certifications filter by category on landing page
vas3a 186fe43
TCA-441 - learn landing filters - mobile UI
vas3a b45076e
Merge branch 'dev' of github.com:topcoder-platform/platform-ui into T…
vas3a 8a59c3f
TCA-441 - update button style for secondary buttons on learn landing …
vas3a 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| export * from './form-input-autcomplete-option.enum' | ||
| export * from './input-rating' | ||
| export * from './input-select' | ||
| export * from './input-text' | ||
| export * from './input-textarea' | ||
| export { inputOptional } from './input-wrapper' |
57 changes: 57 additions & 0 deletions
57
src-ts/lib/form/form-groups/form-input/input-select/InputSelect.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,57 @@ | ||
| @import '../../../../styles/includes'; | ||
|
|
||
| .selected { | ||
| display: flex; | ||
| align-items: center; | ||
| margin-top: $space-xs; | ||
| cursor: pointer; | ||
| color: $black-100; | ||
|
|
||
| &-icon { | ||
| margin-left: auto; | ||
| padding: $border-xs 0; | ||
| color: $turq-160; | ||
| > svg { | ||
| @include icon-size(14); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .menu-wrap { | ||
| position: absolute; | ||
| top: calc(100% - 2px); | ||
| left: 0; | ||
| width: 100%; | ||
| &:not(:empty) { | ||
| z-index: 9; | ||
| } | ||
| } | ||
|
|
||
| .select-menu { | ||
| position: absolute; | ||
| top: 100%; | ||
| left: -1px; | ||
| right: -1px; | ||
| background: $tc-white; | ||
| border: $border-xs solid $black-40; | ||
| border-radius: 0 0 $space-xs $space-xs; | ||
| padding: $space-sm 0; | ||
| max-height: 230px; | ||
| overflow: auto; | ||
| } | ||
|
|
||
| .select-option { | ||
| font-weight: normal; | ||
| color: $black-100; | ||
| padding: $space-sm $space-lg; | ||
|
|
||
| &:hover:global(:not(.selected)) { | ||
| background: $turq-160; | ||
| color: $tc-white; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| &:global(.selected) { | ||
| font-weight: bold; | ||
| } | ||
| } |
104 changes: 104 additions & 0 deletions
104
src-ts/lib/form/form-groups/form-input/input-select/InputSelect.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,104 @@ | ||
| import classNames from 'classnames' | ||
| import { | ||
| ChangeEvent, | ||
| Dispatch, | ||
| FC, | ||
| MutableRefObject, | ||
| ReactNode, | ||
| SetStateAction, | ||
| useRef, | ||
| useState, | ||
| } from 'react' | ||
|
|
||
| import { useClickOutside } from '../../../../hooks' | ||
| import { IconOutline } from '../../../../svgs' | ||
| import { InputWrapper } from '../input-wrapper' | ||
|
|
||
| import styles from './InputSelect.module.scss' | ||
|
|
||
| export interface InputSelectOption { | ||
| label?: ReactNode | ||
| value: string | ||
| } | ||
|
|
||
| interface InputSelectProps { | ||
| 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: Array<InputSelectOption> | ||
| readonly tabIndex?: number | ||
| readonly value?: string | ||
| } | ||
|
|
||
| const InputSelect: FC<InputSelectProps> = (props: InputSelectProps) => { | ||
| const triggerRef: MutableRefObject<any> = useRef(undefined) | ||
| const [menuIsVisible, setMenuIsVisible]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false) | ||
|
|
||
| const selectedOption: InputSelectOption | undefined = props.options.find(option => option.value === props.value) | ||
|
|
||
| const label: (option: InputSelectOption) => ReactNode = (option?: InputSelectOption) => ( | ||
| option ? option.label ?? option.value : '' | ||
| ) | ||
|
|
||
| const toggleMenu: () => void = () => setMenuIsVisible((wasVisible) => !wasVisible) | ||
|
|
||
| const select: (option: InputSelectOption) => () => void = (option: InputSelectOption) => () => { | ||
| props.onChange({ | ||
| target: {value: option.value} , | ||
| } as unknown as ChangeEvent<HTMLInputElement>) | ||
| toggleMenu() | ||
| } | ||
|
|
||
| useClickOutside(triggerRef.current, () => setMenuIsVisible(false)) | ||
|
|
||
| return ( | ||
| <InputWrapper | ||
| {...props} | ||
| dirty={!!props.dirty} | ||
| disabled={!!props.disabled} | ||
| hint={props.hint ?? ''} | ||
| label={props.label ?? ''} | ||
| type='text' | ||
| className={styles['select-input-wrapper']} | ||
| hideInlineErrors={props.hideInlineErrors} | ||
| ref={triggerRef} | ||
| > | ||
| <div className={styles['selected']} onClick={toggleMenu}> | ||
| <span className='body-small'>{selectedOption ? label(selectedOption) : ''}</span> | ||
| <span className={styles['selected-icon']}> | ||
| <IconOutline.ChevronDownIcon /> | ||
| </span> | ||
| </div> | ||
|
|
||
| <div className={styles['menu-wrap']}> | ||
| {menuIsVisible && ( | ||
| <div className={styles['select-menu']}> | ||
| {props.options.map((option) => ( | ||
| <div | ||
| className={ | ||
| classNames( | ||
| styles['select-option'], | ||
| 'body-main', | ||
| selectedOption === option && 'selected', | ||
| ) | ||
| } | ||
| onClick={select(option)} | ||
| key={option.value} | ||
| > | ||
| {label(option)} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| </InputWrapper> | ||
| ) | ||
| } | ||
|
|
||
| export default InputSelect |
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 InputSelect } from './InputSelect' |
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
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from './use-check-is-mobile.hook' | ||
| export * from './use-click-outside.hook' | ||
| export * from './use-on-hover-element.hook' | ||
| export * from './use-storage.hook' | ||
| export * from './use-window-size.hook' |
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,69 @@ | ||
| import { Dispatch, SetStateAction, useCallback, useState } from 'react' | ||
|
|
||
| type StorageTypes = 'localStorage' | 'sessionStorage' | ||
|
|
||
| export function useStorage<T>( | ||
| storageType: StorageTypes, | ||
| storageKey: string, | ||
| initialValue?: T | ||
| ): [T, Dispatch<SetStateAction<T>>] { | ||
| const storage: Storage = window[storageType] | ||
|
|
||
| const readStoredValue: () => T = useCallback(() => { | ||
| try { | ||
| // Get from local storage by key | ||
| const item: string | null = storage.getItem(storageKey) | ||
| // Parse stored json or if none return initialValue | ||
| return item ? JSON.parse(item) : initialValue | ||
| } catch (error) { | ||
| // If error also return value | ||
| return initialValue | ||
| } | ||
| }, [storage, storageKey, initialValue]) | ||
|
|
||
| // State to store our value | ||
| // Pass initial state function to useState so logic is only executed once | ||
| const [storedValue, setStoredValue]: [T, Dispatch<SetStateAction<T>>] = useState(readStoredValue()) | ||
|
|
||
| // Return a wrapped version of useState's setter function that | ||
| // persists the new value to local or session storage. | ||
| const setValue: Dispatch<SetStateAction<T>> = useCallback((value: T) => { | ||
| try { | ||
| // Allow value to be a function so we have same API as useState | ||
| setStoredValue((storedv: T) => { | ||
| const valueToStore: T = value instanceof Function ? value(storedv) : value | ||
|
|
||
| if (valueToStore === undefined) { | ||
| storage.removeItem(storageKey) | ||
| } else { | ||
| // Save to local storage | ||
| storage.setItem(storageKey, JSON.stringify(valueToStore)) | ||
| } | ||
|
|
||
| return valueToStore | ||
| }) | ||
| } catch (error) { | ||
| // A more advanced implementation would handle the error case | ||
| // tslint:disable-next-line:no-console | ||
| console.error(error) | ||
| } | ||
| }, [storage, storageKey]) as Dispatch<SetStateAction<T>> | ||
|
|
||
| return [storedValue, setValue] | ||
| } | ||
|
|
||
| export const useLocalStorage: <T, >( | ||
| key: string, | ||
| initialValue?: T | ||
| ) => [T, Dispatch<SetStateAction<T>>] = <T>( | ||
| key: string, | ||
| initialValue?: T | ||
| ) => useStorage<T>('localStorage', key, initialValue) | ||
|
|
||
| export const useSessionStorage: <T, >( | ||
| key: string, | ||
| initialValue?: T | ||
| ) => [T, Dispatch<SetStateAction<T>>] = <T>( | ||
| key: string, | ||
| initialValue?: T | ||
| ) => useStorage<T>('sessionStorage', key, initialValue) | ||
2 changes: 1 addition & 1 deletion
2
...ols/learn/learn-lib/all-certifications-provider/all-certifications-provider-data.model.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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import { LearnCertification } from './all-certifications-functions' | ||
|
|
||
| export interface AllCertificationsProviderData { | ||
| allCertifications: Array<LearnCertification> | ||
| certification?: LearnCertification | ||
| certifications: Array<LearnCertification> | ||
| certificationsCount: number | ||
| loading: boolean | ||
| ready: boolean | ||
| } |
Oops, something went wrong.
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.
I love this. Nice work!!