diff --git a/packages/web-kitchensink-reactnext/src/categories/number/react/components/Slider/index.tsx b/packages/web-kitchensink-reactnext/src/categories/number/react/components/Slider/index.tsx index fb5258b..34339ce 100644 --- a/packages/web-kitchensink-reactnext/src/categories/number/react/components/Slider/index.tsx +++ b/packages/web-kitchensink-reactnext/src/categories/number/react/components/Slider/index.tsx @@ -1,9 +1,32 @@ import * as React from 'react'; -import * as SelectControlBase from '@tesseract-design/web-base-selectcontrol'; -import {RenderOptions} from '@tesseract-design/web-option-react'; import clsx from 'clsx'; import styles from './style.module.css'; +const filterOptions = (children: React.ReactNode): React.ReactNode => { + const childrenArray = Array.isArray(children) ? children : [children]; + return childrenArray.reduce( + (optionChildren, child) => { + if (!(typeof child === 'object' && child)) { + return optionChildren; + } + if (child.type === 'option') { + return [ + ...optionChildren, + child, + ]; + } + if (child.type === 'optgroup') { + return [ + ...optionChildren, + ...filterOptions(child.props.children) as unknown[], + ]; + } + return optionChildren; + }, + [], + ) as React.ReactNode; +}; + /* * Caveat for slider: * @@ -179,6 +202,10 @@ export const Slider = React.forwardRef(({ return null; } + const childrenValues = children + ? filterOptions(children) + : undefined; + return ( <> { @@ -221,7 +248,7 @@ export const Slider = React.forwardRef(({ min={minValue} max={maxValue} type="range" - list={children ? tickMarkId : undefined} + list={childrenValues ? tickMarkId : undefined} className={clsx( styles.slider, 'w-full h-full bg-inherit block text-primary ring-secondary/50 rounded-full', @@ -229,11 +256,11 @@ export const Slider = React.forwardRef(({ 'active:text-tertiary active:ring-tertiary/50', )} /> - {Array.isArray(children) && ( + {Array.isArray(childrenValues) && (
{ - children + childrenValues .filter((c) => { const value = Number(c.props.value); return minValue <= value && value <= maxValue; @@ -255,7 +282,9 @@ export const Slider = React.forwardRef(({
-
+
{c.props.children}
diff --git a/packages/web-kitchensink-reactnext/src/pages/categories/number/index.tsx b/packages/web-kitchensink-reactnext/src/pages/categories/number/index.tsx index 79b59b6..af5819b 100644 --- a/packages/web-kitchensink-reactnext/src/pages/categories/number/index.tsx +++ b/packages/web-kitchensink-reactnext/src/pages/categories/number/index.tsx @@ -28,19 +28,21 @@ const NumberPage: NextPage = () => { min={-100} max={100} > - - - - + + + + + + @@ -49,19 +51,21 @@ const NumberPage: NextPage = () => { max={100} orient="vertical" > - - - - + + + + + + A diff --git a/packages/web-kitchensink-reactnext/src/pages/categories/option/index.tsx b/packages/web-kitchensink-reactnext/src/pages/categories/option/index.tsx index fca8afd..b235994 100644 --- a/packages/web-kitchensink-reactnext/src/pages/categories/option/index.tsx +++ b/packages/web-kitchensink-reactnext/src/pages/categories/option/index.tsx @@ -2,52 +2,28 @@ import { NextPage } from 'next'; import * as Option from '@tesseract-design/web-option-react'; import * as SelectControlBase from '@tesseract-design/web-base-selectcontrol'; import { DefaultLayout } from '@/components/DefaultLayout'; +import {ReactNode} from 'react'; type Props = { - options: SelectControlBase.SelectOption[], + options: ReactNode, } const OptionPage: NextPage = ({ - options = [ - { - label: 'Fruits', - children: [ - { - label: 'Mango', - value: 'mango', - }, - { - label: 'Strawberry', - value: 'strawberry', - }, - { - label: 'Avocado', - value: 'avocado', - }, - { - label: 'Grapes', - value: 'grapes', - }, - ], - }, - { - label: 'Non-fruits', - children: [ - { - label: 'Chocolate', - value: 'chocolate', - }, - { - label: 'Milk', - value: 'milk', - }, - { - label: 'Coffee', - value: 'coffee', - }, - ], - }, - ], + options = ( + <> + + + + + + + + + + + + + ) }) => { return ( = ({ hint="Type anything here…" block > - + {options}
@@ -85,16 +59,18 @@ const OptionPage: NextPage = ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
+ > + {options} +
= ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" block disabled - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" block disabled - options={options} - /> + > + {options} +
@@ -222,8 +203,9 @@ const OptionPage: NextPage = ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ label="Select" hint="Type anything here…" block - options={options} - /> + > + {options} +
= ({ size="large" label="Select" hint="Type anything here…" - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" block disabled - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" block disabled - options={options} - /> + > + {options} +
@@ -322,8 +311,9 @@ const OptionPage: NextPage = ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ indicator="A" block disabled - options={options} - /> + > + {options} +
= ({ indicator="A" block disabled - options={options} - /> + > + {options} +
@@ -412,8 +409,9 @@ const OptionPage: NextPage = ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} - /> + > + {options} +
= ({ label="MultilineTextInput" hint="Type anything here…" indicator="A" - options={options} - /> + > + {options} +
= ({ indicator="A" block disabled - options={options} - /> + > + {options} +
= ({ indicator="A" block disabled - options={options} - /> + > + {options} +
@@ -510,9 +515,10 @@ const OptionPage: NextPage = ({ hint="Type anything here…" indicator="A" block - options={options} multiple - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} multiple - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} multiple - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} multiple - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} multiple - /> + > + {options} +
= ({ hint="Type anything here…" indicator="A" block - options={options} multiple - /> + > + {options} +
= ({ indicator="A" block disabled - options={options} multiple - /> + > + {options} +
= ({ indicator="A" block disabled - options={options} multiple - /> + > + {options} +