diff --git a/apps/storybook/stories/text-input.stories.tsx b/apps/storybook/stories/text-input.stories.tsx index bb5a9220..6cac0b60 100644 --- a/apps/storybook/stories/text-input.stories.tsx +++ b/apps/storybook/stories/text-input.stories.tsx @@ -5,7 +5,7 @@ import { QuestionMarkCircleIcon, } from '@heroicons/react/24/solid'; import type { ComponentMeta } from '@storybook/react'; -import { TextInput } from '@tih/ui'; +import { Select, TextInput } from '@tih/ui'; export default { argTypes: { @@ -70,7 +70,8 @@ export function Email() { +
+ + + } + endAddOnType="element" + label="Price" + placeholder="0.00" + startAddOn="$" + startAddOnType="label" + type="text" + /> +
); } @@ -134,10 +168,97 @@ export function Error() { value.length < 6 ? 'Password must be at least 6 characters' : undefined } label="Email" - startIcon={KeyIcon} + startAddOn={KeyIcon} + startAddOnType="icon" type="password" value={value} onChange={setValue} /> ); } + +export function AddOns() { + return ( +
+ + + + + } + startAddOnType="element" + type="text" + /> + + } + endAddOnType="element" + label="Price" + placeholder="0.00" + startAddOn="$" + startAddOnType="label" + type="text" + /> +
+ ); +} diff --git a/packages/ui/src/Select/Select.tsx b/packages/ui/src/Select/Select.tsx index 294ae34d..67acf5a9 100644 --- a/packages/ui/src/Select/Select.tsx +++ b/packages/ui/src/Select/Select.tsx @@ -14,8 +14,10 @@ export type SelectItem = Readonly<{ }>; export type SelectDisplay = 'block' | 'inline'; +export type SelectBorderStyle = 'bordered' | 'borderless'; type Props = Readonly<{ + borderStyle?: SelectBorderStyle; defaultValue?: T; display?: SelectDisplay; isLabelHidden?: boolean; @@ -27,8 +29,14 @@ type Props = Readonly<{ }> & Readonly; +const borderClasses: Record = { + bordered: 'border-slate-300', + borderless: 'border-transparent bg-transparent', +}; + function Select( { + borderStyle = 'bordered', defaultValue, display, disabled, @@ -45,20 +53,20 @@ function Select( return (
- + {!isLabelHidden && ( + + )} - {EndIcon && ( -
-
- )} + {(() => { + if (endAddOnType == null) { + return; + } + + switch (endAddOnType) { + case 'label': + return ( +
+ {endAddOn} +
+ ); + case 'icon': { + const EndAddOn = endAddOn; + return ( +
+
+ ); + } + case 'element': + return endAddOn; + } + })()}
{errorMessage && (