diff --git a/src/components/pages/about-page/AboutPage.tsx b/src/components/pages/about-page/AboutPage.tsx index dc81af1..d6848be 100644 --- a/src/components/pages/about-page/AboutPage.tsx +++ b/src/components/pages/about-page/AboutPage.tsx @@ -1,14 +1,41 @@ -import React from 'react'; +import React, { useState } from 'react'; import Link from 'next/link'; import { Routes } from '../../../constants/Routes'; +import { UiSelect } from '../../ui/ui-select/UiSelect'; interface IProps {} export const AboutPage: React.FC = (props) => { + const [controlledValue, setControlledValue] = useState('3'); + return (

About

This is the about page

+
+ console.log(value, typeof value)} + initialValue="2" + options={[ + { label: 'One', value: '1' }, + { label: 'Two', value: '2' }, + { label: 'Three', value: '3' }, + { label: 'Four', value: '4' }, + ]} + /> + setControlledValue(value)} + value={controlledValue} + options={[ + { label: 'One', value: '1' }, + { label: 'Two', value: '2' }, + { label: 'Three', value: '3' }, + { label: 'Four', value: '4' }, + ]} + /> +

Go home diff --git a/src/components/ui/ui-select/UiSelect.constants.ts b/src/components/ui/ui-select/UiSelect.constants.ts new file mode 100644 index 0000000..226859d --- /dev/null +++ b/src/components/ui/ui-select/UiSelect.constants.ts @@ -0,0 +1,4 @@ +export interface IUiSelectOptions { + label: string; + value: string | number; +} diff --git a/src/components/ui/ui-select/UiSelect.tsx b/src/components/ui/ui-select/UiSelect.tsx new file mode 100644 index 0000000..224aef8 --- /dev/null +++ b/src/components/ui/ui-select/UiSelect.tsx @@ -0,0 +1,44 @@ +import React, { useEffect, useState } from 'react'; +import { IUiSelectOptions } from './UiSelect.constants'; +import { noop } from '../../../utils/misc.utils'; + +interface IProps { + options: IUiSelectOptions[]; + /** + * If a value is passed in then the component is considered controlled. + */ + value?: string; + id?: string; + name?: string; + onChange?: (value: string) => void; + initialValue?: string; +} + +export const UiSelect: React.FC = (props) => { + const [selected, setSelected] = useState(props.value || props.initialValue); + + useEffect(() => { + setSelected(props.value); + }, [props.value]); + + return ( + + ); +}; + +UiSelect.defaultProps = { + onChange: noop, +};