Skip to content

Commit

Permalink
Merge pull request #229 from Exlint/EDSelect
Browse files Browse the repository at this point in the history
Ed select
  • Loading branch information
tal-rofe committed Aug 16, 2022
2 parents 1216bc1 + 605000c commit e532522
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/frontend/src/assets/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const icons = {
'18 18',
'<path d="M2.44531 17.0312H10.3359C11.138 17.0312 11.7448 16.8229 12.1562 16.4062C12.5729 15.9896 12.7812 15.3776 12.7812 14.5703V11.2812H11.2188V14.4453C11.2188 14.7786 11.1328 15.0312 10.9609 15.2031C10.7891 15.3802 10.5286 15.4688 10.1797 15.4688H2.60156C2.2526 15.4688 1.99219 15.3802 1.82031 15.2031C1.65365 15.0312 1.57031 14.7786 1.57031 14.4453V3.5625C1.57031 3.22917 1.65365 2.97656 1.82031 2.80469C1.99219 2.6276 2.2526 2.53906 2.60156 2.53906H10.1797C10.5286 2.53906 10.7891 2.6276 10.9609 2.80469C11.1328 2.97656 11.2188 3.22917 11.2188 3.5625V6.73438H12.7812V3.44531C12.7812 2.63281 12.5729 2.01823 12.1562 1.60156C11.7448 1.17969 11.138 0.96875 10.3359 0.96875H2.44531C1.64844 0.96875 1.04167 1.17969 0.625 1.60156C0.208333 2.01823 0 2.63281 0 3.44531V14.5703C0 15.3776 0.208333 15.9896 0.625 16.4062C1.04167 16.8229 1.64844 17.0312 2.44531 17.0312ZM7.3125 9.72656H14.6953L15.7891 9.66406L15.2422 10.1094L14.1719 11.1094C14.0312 11.2344 13.9609 11.3958 13.9609 11.5938C13.9609 11.7656 14.0182 11.9167 14.1328 12.0469C14.2474 12.1719 14.3958 12.2344 14.5781 12.2344C14.7448 12.2344 14.8958 12.1667 15.0312 12.0312L17.4141 9.55469C17.5078 9.46094 17.5729 9.36979 17.6094 9.28125C17.6458 9.1875 17.6641 9.09375 17.6641 9C17.6641 8.90104 17.6458 8.80729 17.6094 8.71875C17.5729 8.625 17.5078 8.53385 17.4141 8.44531L15.0312 5.96875C14.8958 5.83333 14.7448 5.76562 14.5781 5.76562C14.3958 5.76562 14.2474 5.82812 14.1328 5.95312C14.0182 6.07812 13.9609 6.22917 13.9609 6.40625C13.9609 6.59896 14.0312 6.76042 14.1719 6.89062L15.2422 7.89062L15.7891 8.33594L14.6953 8.27344H7.3125C7.11979 8.27344 6.95052 8.34375 6.80469 8.48438C6.66406 8.625 6.59375 8.79688 6.59375 9C6.59375 9.19792 6.66406 9.36979 6.80469 9.51562C6.95052 9.65625 7.11979 9.72656 7.3125 9.72656Z"/>',
],
arrowRight: [
'13 22',
`
<path d="M1 20.5L11.1237 11.7568C11.5855 11.358 11.5855 10.642 11.1237 10.2432L0.999999 1.5"/>
`,
],
};

export default icons;
61 changes: 61 additions & 0 deletions apps/frontend/src/components/ui/EDSelect/EDSelect.module.scss
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;
}
}
}
44 changes: 44 additions & 0 deletions apps/frontend/src/components/ui/EDSelect/EDSelect.tsx
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 apps/frontend/src/components/ui/EDSelect/EDSelect.view.tsx
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);
3 changes: 3 additions & 0 deletions apps/frontend/src/components/ui/EDSelect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import EDSelect from './EDSelect';

export default EDSelect;

0 comments on commit e532522

Please sign in to comment.