-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from Exlint/EDSelect
Ed select
- Loading branch information
Showing
5 changed files
with
180 additions
and
0 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
61 changes: 61 additions & 0 deletions
61
apps/frontend/src/components/ui/EDSelect/EDSelect.module.scss
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,61 @@ | ||
.container { | ||
position: relative; | ||
width: 200px; | ||
|
||
.buttonContainer { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
width: 100%; | ||
padding: 10px 14px; | ||
background-color: #fefefe; | ||
border: 2px solid #e7e7e7; | ||
|
||
&--tooltipIsVisible { | ||
border-start-start-radius: 10px; | ||
border-start-end-radius: 10px; | ||
} | ||
|
||
&--tooltipIsInvisible { | ||
border-radius: 10px; | ||
} | ||
|
||
&__text { | ||
font-size: 1.5rem; | ||
font-weight: 360; | ||
color: #4b4a65; | ||
} | ||
|
||
&__arrow { | ||
width: auto; | ||
height: 8px; | ||
fill: transparent; | ||
stroke: #202428; | ||
stroke-linecap: round; | ||
stroke-width: 2; | ||
transition: transform 0.3s ease; | ||
|
||
&--tooltipIsVisible { | ||
transform: rotate(90deg); | ||
} | ||
} | ||
} | ||
|
||
.optionsContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
padding: 10px 14px; | ||
background-color: #fefefe; | ||
border: 2px solid #e7e7e7; | ||
border-top: none; | ||
border-end-start-radius: 10px; | ||
border-end-end-radius: 10px; | ||
|
||
&__option { | ||
font-size: 1.5rem; | ||
font-weight: 360; | ||
color: #4b4a65; | ||
} | ||
} | ||
} |
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 @@ | ||
import React from 'react'; | ||
|
||
import { useClickOutside } from '@/hooks/click-outside'; | ||
|
||
import EdSelectView from './EDSelect.view'; | ||
|
||
interface IProps { | ||
readonly className?: string; | ||
readonly placeholder?: string; | ||
readonly options: string[]; | ||
readonly selectedOptionIndex: number | null; | ||
readonly onOptionSelect: (index: number) => void; | ||
} | ||
|
||
const EDSelect: React.FC<IProps> = (props: React.PropsWithChildren<IProps>) => { | ||
const { | ||
ref: tooltopRef, | ||
isVisible: isTooltipVisible, | ||
toggleVisibility: toggleTooltipVisibility, | ||
} = useClickOutside<HTMLDivElement>(false); | ||
|
||
const onOptionSelect = (index: number) => { | ||
props.onOptionSelect(index); | ||
toggleTooltipVisibility(); | ||
}; | ||
|
||
return ( | ||
<EdSelectView | ||
className={props.className} | ||
placeholder={props.placeholder} | ||
options={props.options} | ||
selectedOptionIndex={props.selectedOptionIndex} | ||
tooltopRef={tooltopRef} | ||
isTooltipVisible={isTooltipVisible} | ||
toggleTooltipVisibility={toggleTooltipVisibility} | ||
onOptionSelect={onOptionSelect} | ||
/> | ||
); | ||
}; | ||
|
||
EDSelect.displayName = 'EDSelect'; | ||
EDSelect.defaultProps = {}; | ||
|
||
export default React.memo(EDSelect); |
66 changes: 66 additions & 0 deletions
66
apps/frontend/src/components/ui/EDSelect/EDSelect.view.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,66 @@ | ||
import React from 'react'; | ||
|
||
import { concatClasses, concatDiverseClasses } from '@/utils/component'; | ||
import EDSvg from '@/ui/EDSvg'; | ||
|
||
import classes from './EDSelect.module.scss'; | ||
|
||
interface IProps { | ||
readonly className?: string; | ||
readonly placeholder?: string; | ||
readonly options: string[]; | ||
readonly selectedOptionIndex: number | null; | ||
readonly tooltopRef: React.RefObject<HTMLDivElement>; | ||
readonly isTooltipVisible: boolean; | ||
readonly toggleTooltipVisibility: () => void; | ||
readonly onOptionSelect: (index: number) => void; | ||
} | ||
|
||
const EDSelectView: React.FC<IProps> = (props: React.PropsWithChildren<IProps>) => { | ||
const containerClasses = concatDiverseClasses(classes['container'], props.className); | ||
|
||
const buttonContainerClasses = concatClasses( | ||
classes, | ||
'buttonContainer', | ||
props.isTooltipVisible ? 'buttonContainer--tooltipIsVisible' : 'buttonContainer--tooltipIsInvisible', | ||
); | ||
|
||
const selectArrowIconClasses = concatClasses( | ||
classes, | ||
'buttonContainer__arrow', | ||
props.isTooltipVisible ? 'buttonContainer__arrow--tooltipIsVisible' : null, | ||
); | ||
|
||
const selectText = props.selectedOptionIndex | ||
? props.options[props.selectedOptionIndex] | ||
: props.placeholder ?? props.options[0]; | ||
|
||
return ( | ||
<div className={containerClasses}> | ||
<button className={buttonContainerClasses} type="button" onClick={props.toggleTooltipVisibility}> | ||
<span className={classes['buttonContainer__text']}>{selectText}</span> | ||
|
||
<EDSvg className={selectArrowIconClasses} name="arrowRight" /> | ||
</button> | ||
{props.isTooltipVisible && ( | ||
<div ref={props.tooltopRef} className={classes['optionsContainer']}> | ||
{props.options.map((option, index) => ( | ||
<button | ||
key={index} | ||
className={classes['optionsContainer__option']} | ||
type="button" | ||
onClick={() => props.onOptionSelect(index)} | ||
> | ||
{option} | ||
</button> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
EDSelectView.displayName = 'EDSelectView'; | ||
EDSelectView.defaultProps = {}; | ||
|
||
export default React.memo(EDSelectView); |
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 @@ | ||
import EDSelect from './EDSelect'; | ||
|
||
export default EDSelect; |