Add menuselect starting height, as well as remove extra code for option elements.pull/1/head
@@ -1,8 +1,6 @@ | |||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import * as TextControlBase from '@tesseract-design/web-base-textcontrol'; | import * as TextControlBase from '@tesseract-design/web-base-textcontrol'; | ||||
import * as SelectControlBase from '@tesseract-design/web-base-selectcontrol'; | |||||
import clsx from 'clsx'; | import clsx from 'clsx'; | ||||
import {RenderOptions} from '@/categories/option/react'; | |||||
export type DropdownSelectDerivedElement = HTMLSelectElement; | export type DropdownSelectDerivedElement = HTMLSelectElement; | ||||
@@ -43,7 +41,6 @@ export interface DropdownSelectProps extends Omit<React.HTMLProps<DropdownSelect | |||||
* Is the label hidden? | * Is the label hidden? | ||||
*/ | */ | ||||
hiddenLabel?: boolean, | hiddenLabel?: boolean, | ||||
options?: SelectControlBase.SelectOption[], | |||||
} | } | ||||
/** | /** | ||||
@@ -64,14 +61,12 @@ export const DropdownSelect = React.forwardRef<DropdownSelectDerivedElement, Dro | |||||
variant = 'default' as const, | variant = 'default' as const, | ||||
hiddenLabel = false, | hiddenLabel = false, | ||||
className, | className, | ||||
options = [], | |||||
children, | children, | ||||
...etcProps | ...etcProps | ||||
}: DropdownSelectProps, | }: DropdownSelectProps, | ||||
ref, | ref, | ||||
) => { | ) => { | ||||
const labelId = React.useId(); | const labelId = React.useId(); | ||||
console.log(children); | |||||
return ( | return ( | ||||
<div | <div | ||||
@@ -37,6 +37,7 @@ export interface MenuSelectProps extends Omit<React.HTMLProps<MenuSelectDerivedE | |||||
* Is the label hidden? | * Is the label hidden? | ||||
*/ | */ | ||||
hiddenLabel?: boolean, | hiddenLabel?: boolean, | ||||
startingHeight?: number | string, | |||||
} | } | ||||
/** | /** | ||||
@@ -56,6 +57,7 @@ export const MenuSelect = React.forwardRef<MenuSelectDerivedElement, MenuSelectP | |||||
variant = 'default' as const, | variant = 'default' as const, | ||||
hiddenLabel = false, | hiddenLabel = false, | ||||
className, | className, | ||||
startingHeight = '15rem', | |||||
...etcProps | ...etcProps | ||||
}: MenuSelectProps, | }: MenuSelectProps, | ||||
ref, | ref, | ||||
@@ -81,10 +83,10 @@ export const MenuSelect = React.forwardRef<MenuSelectDerivedElement, MenuSelectP | |||||
data-testid="input" | data-testid="input" | ||||
size={2} | size={2} | ||||
style={{ | style={{ | ||||
height: 0, | |||||
height: startingHeight, | |||||
}} | }} | ||||
className={clsx( | className={clsx( | ||||
'bg-negative rounded-inherit w-full peer block', | |||||
'bg-negative rounded-inherit w-full peer block overflow-auto', | |||||
'focus:outline-0', | 'focus:outline-0', | ||||
'disabled:opacity-50 disabled:cursor-not-allowed', | 'disabled:opacity-50 disabled:cursor-not-allowed', | ||||
{ | { | ||||
@@ -1,76 +0,0 @@ | |||||
import * as SelectControlBase from '@/base/selectcontrol'; | |||||
import * as React from 'react'; | |||||
export interface RenderOptionsProps { | |||||
options: SelectControlBase.SelectOption[], | |||||
optionComponent?: React.ElementType, | |||||
optgroupComponent?: React.ElementType, | |||||
level?: number, | |||||
} | |||||
export const RenderOptions: React.FC<RenderOptionsProps> = ({ | |||||
options, | |||||
optionComponent: Option = 'option', | |||||
optgroupComponent: Optgroup = 'optgroup', | |||||
level = 0, | |||||
}: RenderOptionsProps) => ( | |||||
options.map((o) => { | |||||
if (typeof o === 'number' || typeof o === 'string') { | |||||
return ( | |||||
<Option | |||||
key={`${o}:${o}`} | |||||
value={o} | |||||
/> | |||||
); | |||||
} | |||||
if (typeof o.value !== 'undefined') { | |||||
return ( | |||||
<Option | |||||
key={`${o.label}:${o.value.toString()}`} | |||||
value={o.value} | |||||
label={o.label} | |||||
> | |||||
{o.label} | |||||
</Option> | |||||
); | |||||
} | |||||
if (typeof o.children !== 'undefined') { | |||||
if (level === 0) { | |||||
return ( | |||||
<Optgroup | |||||
key={o.label} | |||||
label={o.label} | |||||
> | |||||
<RenderOptions | |||||
options={o.children} | |||||
optionComponent={Option} | |||||
optgroupComponent={Optgroup} | |||||
level={level + 1} | |||||
/> | |||||
</Optgroup> | |||||
); | |||||
} | |||||
return ( | |||||
<React.Fragment | |||||
key={o.label} | |||||
> | |||||
<Option | |||||
disabled | |||||
> | |||||
{o.label} | |||||
</Option> | |||||
<RenderOptions | |||||
options={o.children} | |||||
optionComponent={Option} | |||||
optgroupComponent={Optgroup} | |||||
level={level + 1} | |||||
/> | |||||
</React.Fragment> | |||||
); | |||||
} | |||||
return null; | |||||
}) | |||||
); |
@@ -3,7 +3,6 @@ export * from './components/DropdownSelect'; | |||||
export * from './components/MenuSelect'; | export * from './components/MenuSelect'; | ||||
export * from './components/RadioButton'; | export * from './components/RadioButton'; | ||||
export * from './components/RadioTickBox'; | export * from './components/RadioTickBox'; | ||||
export * from './components/RenderOptions'; | |||||
export * from './components/TagInput'; | export * from './components/TagInput'; | ||||
export * from './components/ToggleButton'; | export * from './components/ToggleButton'; | ||||
export * from './components/ToggleSwitch'; | export * from './components/ToggleSwitch'; | ||||