Compare commits

...

1 Commits

Author SHA1 Message Date
29a4e8c2ee add width, v0.1.10
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing
2026-02-23 19:57:19 +01:00
10 changed files with 68 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@panic/web-ui", "name": "@panic/web-ui",
"version": "0.1.9", "version": "0.1.10",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"description": "Core components for panic.haus web applications", "description": "Core components for panic.haus web applications",
"type": "module", "type": "module",

View File

@@ -39,6 +39,12 @@ const meta = {
control: 'inline-radio', control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } }, table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
}, },
width: {
description: 'Button width behavior.',
options: ['sm', 'md', 'lg', 'full'],
control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
},
to: { to: {
description: 'Navigation path. When set, the component renders a `<Link>`.', description: 'Navigation path. When set, the component renders a `<Link>`.',
control: 'text', control: 'text',
@@ -80,6 +86,7 @@ const meta = {
type: 'solid', type: 'solid',
variant: 'primary', variant: 'primary',
size: 'md', size: 'md',
width: 'md',
label: 'Save', label: 'Save',
}, },
} satisfies Meta<typeof Button>; } satisfies Meta<typeof Button>;
@@ -132,7 +139,7 @@ export const SizeMatrix: Story = {
<Button {...args} size="sm" label="Small" /> <Button {...args} size="sm" label="Small" />
<Button {...args} size="md" label="Medium" /> <Button {...args} size="md" label="Medium" />
<Button {...args} size="lg" label="Large" /> <Button {...args} size="lg" label="Large" />
<Button {...args} size="full" label="Full width" /> <Button {...args} size="md" width="full" label="Full width" />
</div> </div>
), ),
}; };

View File

@@ -11,6 +11,7 @@ type ButtonProps = {
type: ButtonType; type: ButtonType;
variant?: ButtonVariant; variant?: ButtonVariant;
size?: ComponentSize; size?: ComponentSize;
width?: ComponentSize;
to?: string; to?: string;
htmlType?: NativeButtonType; htmlType?: NativeButtonType;
onClick?: MouseEventHandler<HTMLElement>; onClick?: MouseEventHandler<HTMLElement>;
@@ -24,14 +25,14 @@ const SIZE_CLASS: Record<ComponentSize, string> = {
sm: 'h-8 px-3 text-xs', sm: 'h-8 px-3 text-xs',
md: 'h-10 px-4 text-sm', md: 'h-10 px-4 text-sm',
lg: 'h-12 px-5 text-base', lg: 'h-12 px-5 text-base',
full: 'h-10 w-full px-4 text-sm', full: 'h-10 px-4 text-sm',
}; };
const ICON_ONLY_SIZE_CLASS: Record<ComponentSize, string> = { const ICON_ONLY_SIZE_CLASS: Record<ComponentSize, string> = {
sm: 'h-8 w-8 !p-0', sm: 'h-8 w-8 !p-0',
md: 'h-10 w-10 !p-0', md: 'h-10 w-10 !p-0',
lg: 'h-12 w-12 !p-0', lg: 'h-12 w-12 !p-0',
full: 'h-10 w-full !p-0', full: 'h-10 w-10 !p-0',
}; };
const ICON_CLASS: Record<ComponentSize, string> = { const ICON_CLASS: Record<ComponentSize, string> = {
@@ -48,6 +49,13 @@ const ICON_ONLY_CLASS: Record<ComponentSize, string> = {
full: 'h-5 w-5', full: 'h-5 w-5',
}; };
const WIDTH_CLASS: Record<ComponentSize, string> = {
sm: 'max-w-xs',
md: '',
lg: 'max-w-md',
full: 'w-full max-w-none',
};
const TYPE_CLASS: Record<ButtonType, string> = { const TYPE_CLASS: Record<ButtonType, string> = {
solid: 'btn-solid', solid: 'btn-solid',
outlined: 'btn-outlined', outlined: 'btn-outlined',
@@ -73,6 +81,7 @@ export function Button({
type, type,
variant, variant,
size = 'md', size = 'md',
width = 'md',
to, to,
htmlType = 'button', htmlType = 'button',
onClick, onClick,
@@ -87,6 +96,7 @@ export function Button({
TYPE_CLASS[type], TYPE_CLASS[type],
VARIANT_CLASS[resolvedVariant], VARIANT_CLASS[resolvedVariant],
isIconOnly ? ICON_ONLY_SIZE_CLASS[size] : SIZE_CLASS[size], isIconOnly ? ICON_ONLY_SIZE_CLASS[size] : SIZE_CLASS[size],
WIDTH_CLASS[width],
Icon && label ? 'gap-1.5' : '', Icon && label ? 'gap-1.5' : '',
disabled ? 'pointer-events-none cursor-not-allowed opacity-45 saturate-50' : '', disabled ? 'pointer-events-none cursor-not-allowed opacity-45 saturate-50' : '',
className, className,

View File

@@ -38,6 +38,12 @@ const meta = {
control: 'inline-radio', control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } }, table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
}, },
width: {
description: 'Input width constraint.',
options: ['sm', 'md', 'lg', 'full'],
control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
},
layout: { layout: {
description: 'Label/input layout mode.', description: 'Label/input layout mode.',
options: ['stacked', 'inline'], options: ['stacked', 'inline'],
@@ -105,6 +111,7 @@ const meta = {
type: 'datetime-local', type: 'datetime-local',
value: '', value: '',
size: 'md', size: 'md',
width: 'md',
layout: 'stacked', layout: 'stacked',
}, },
} satisfies Meta<typeof DatePicker>; } satisfies Meta<typeof DatePicker>;
@@ -224,6 +231,7 @@ export const SizeMatrix: Story = {
{...args} {...args}
value={value} value={value}
size="full" size="full"
width="full"
onChange={(event) => setValue(event.target.value)} onChange={(event) => setValue(event.target.value)}
/> />
</div> </div>

View File

@@ -9,6 +9,7 @@ export type DatePickerProps = {
placeholder?: string; placeholder?: string;
type: DatePickerKind; type: DatePickerKind;
size?: ComponentSize; size?: ComponentSize;
width?: ComponentSize;
layout?: Layout; layout?: Layout;
value: string; value: string;
name?: string; name?: string;
@@ -28,6 +29,7 @@ export function DatePicker({
placeholder = '', placeholder = '',
type, type,
size = 'md', size = 'md',
width = 'md',
layout = 'stacked', layout = 'stacked',
value, value,
name, name,
@@ -41,12 +43,12 @@ export function DatePicker({
className = '', className = '',
inputClassName = '', inputClassName = '',
}: Readonly<DatePickerProps>) { }: Readonly<DatePickerProps>) {
const containerSizeClass = { const containerWidthClass = {
sm: 'max-w-xs', sm: 'max-w-xs',
md: 'max-w-sm', md: 'max-w-sm',
lg: 'max-w-md', lg: 'max-w-md',
full: 'max-w-none', full: 'max-w-none',
}[size]; }[width];
const inputSizeClass = { const inputSizeClass = {
sm: 'h-8 !text-xs', sm: 'h-8 !text-xs',
@@ -63,7 +65,7 @@ export function DatePicker({
return ( return (
<label <label
className={`${wrapperClass} text-sm font-medium ${disabled ? 'ui-label-disabled' : 'ui-label'} ${containerSizeClass} ${className}`.trim()} className={`${wrapperClass} text-sm font-medium ${disabled ? 'ui-label-disabled' : 'ui-label'} ${containerWidthClass} ${className}`.trim()}
> >
{label ? <span className={labelClass}>{label}</span> : null} {label ? <span className={labelClass}>{label}</span> : null}
<div className={inputWrapperClass}> <div className={inputWrapperClass}>

View File

@@ -42,6 +42,12 @@ const meta = {
control: 'inline-radio', control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } }, table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
}, },
width: {
description: 'Control width constraint.',
options: ['sm', 'md', 'lg', 'full'],
control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
},
layout: { layout: {
description: 'Label/control layout mode.', description: 'Label/control layout mode.',
options: ['stacked', 'inline'], options: ['stacked', 'inline'],
@@ -84,6 +90,7 @@ const meta = {
value: 'draft', value: 'draft',
choices, choices,
size: 'md', size: 'md',
width: 'md',
layout: 'stacked', layout: 'stacked',
}, },
} satisfies Meta<typeof Dropdown>; } satisfies Meta<typeof Dropdown>;
@@ -147,7 +154,14 @@ export const SizeMatrix: Story = {
<Dropdown {...args} value={value} size="sm" label="Small" onChange={setValue} /> <Dropdown {...args} value={value} size="sm" label="Small" onChange={setValue} />
<Dropdown {...args} value={value} size="md" label="Medium" onChange={setValue} /> <Dropdown {...args} value={value} size="md" label="Medium" onChange={setValue} />
<Dropdown {...args} value={value} size="lg" label="Large" onChange={setValue} /> <Dropdown {...args} value={value} size="lg" label="Large" onChange={setValue} />
<Dropdown {...args} value={value} size="full" label="Full" onChange={setValue} /> <Dropdown
{...args}
value={value}
size="full"
width="full"
label="Full"
onChange={setValue}
/>
</div> </div>
); );
}, },

View File

@@ -14,6 +14,7 @@ type DropdownProps = {
value: string; value: string;
choices: DropdownChoice[]; choices: DropdownChoice[];
size?: ComponentSize; size?: ComponentSize;
width?: ComponentSize;
layout?: DropdownLayout; layout?: DropdownLayout;
disabled?: boolean; disabled?: boolean;
required?: boolean; required?: boolean;
@@ -28,6 +29,7 @@ export function Dropdown({
value, value,
choices, choices,
size = 'md', size = 'md',
width = 'md',
layout = 'stacked', layout = 'stacked',
disabled = false, disabled = false,
required = false, required = false,
@@ -36,12 +38,12 @@ export function Dropdown({
className = '', className = '',
selectClassName = '', selectClassName = '',
}: Readonly<DropdownProps>) { }: Readonly<DropdownProps>) {
const containerSizeClass = { const containerWidthClass = {
sm: 'max-w-xs', sm: 'max-w-xs',
md: 'max-w-sm', md: 'max-w-sm',
lg: 'max-w-md', lg: 'max-w-md',
full: 'max-w-none', full: 'max-w-none',
}[size]; }[width];
const selectSizeClass = { const selectSizeClass = {
sm: 'h-8 !text-xs', sm: 'h-8 !text-xs',
@@ -62,7 +64,7 @@ export function Dropdown({
return ( return (
<label <label
className={`${wrapperClass} text-sm font-medium ${disabled ? 'ui-label-disabled' : 'ui-label'} ${containerSizeClass} ${className}`.trim()} className={`${wrapperClass} text-sm font-medium ${disabled ? 'ui-label-disabled' : 'ui-label'} ${containerWidthClass} ${className}`.trim()}
> >
{label ? <span className={labelClass}>{label}</span> : null} {label ? <span className={labelClass}>{label}</span> : null}
<div className={selectWrapperClass}> <div className={selectWrapperClass}>

View File

@@ -80,6 +80,7 @@ export const WithActions: Story = {
value={title} value={title}
onChange={(event) => setTitle(event.target.value)} onChange={(event) => setTitle(event.target.value)}
size="full" size="full"
width="full"
/> />
</div> </div>
<Dropdown <Dropdown

View File

@@ -38,6 +38,12 @@ const meta = {
control: 'inline-radio', control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } }, table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
}, },
width: {
description: 'Input width constraint.',
options: ['sm', 'md', 'lg', 'full'],
control: 'inline-radio',
table: { type: { summary: "'sm' | 'md' | 'lg' | 'full'" } },
},
layout: { layout: {
description: 'Label/input layout mode.', description: 'Label/input layout mode.',
options: ['stacked', 'inline'], options: ['stacked', 'inline'],
@@ -107,6 +113,7 @@ const meta = {
placeholder: 'name@example.com', placeholder: 'name@example.com',
value: '', value: '',
size: 'md', size: 'md',
width: 'md',
layout: 'stacked', layout: 'stacked',
}, },
} satisfies Meta<typeof InputField>; } satisfies Meta<typeof InputField>;
@@ -229,6 +236,7 @@ export const SizeMatrix: Story = {
{...args} {...args}
value={value} value={value}
size="full" size="full"
width="full"
onChange={(event) => setValue(event.target.value)} onChange={(event) => setValue(event.target.value)}
/> />
</div> </div>

View File

@@ -12,6 +12,7 @@ type InputFieldProps = {
placeholder?: string; placeholder?: string;
type: InputKind; type: InputKind;
size?: ComponentSize; size?: ComponentSize;
width?: ComponentSize;
layout?: Layout; layout?: Layout;
value: string; value: string;
name?: string; name?: string;
@@ -31,6 +32,7 @@ export function InputField({
placeholder = '', placeholder = '',
type, type,
size = 'md', size = 'md',
width = 'md',
layout = 'stacked', layout = 'stacked',
value, value,
name, name,
@@ -45,12 +47,12 @@ export function InputField({
inputClassName = '', inputClassName = '',
}: Readonly<InputFieldProps>) { }: Readonly<InputFieldProps>) {
const [showPassword, setShowPassword] = useState(false); const [showPassword, setShowPassword] = useState(false);
const containerSizeClass = { const containerWidthClass = {
sm: 'max-w-xs', sm: 'max-w-xs',
md: 'max-w-sm', md: 'max-w-sm',
lg: 'max-w-md', lg: 'max-w-md',
full: 'max-w-none', full: 'max-w-none',
}[size]; }[width];
const inputSizeClass = { const inputSizeClass = {
sm: 'h-8 !text-xs', sm: 'h-8 !text-xs',
@@ -69,7 +71,7 @@ export function InputField({
return ( return (
<label <label
className={`${wrapperClass} text-sm font-medium ${disabled ? 'ui-label-disabled' : 'ui-label'} ${containerSizeClass} ${className}`.trim()} className={`${wrapperClass} text-sm font-medium ${disabled ? 'ui-label-disabled' : 'ui-label'} ${containerWidthClass} ${className}`.trim()}
> >
{label ? <span className={labelClass}>{label}</span> : null} {label ? <span className={labelClass}>{label}</span> : null}
<div className={inputWrapperClass}> <div className={inputWrapperClass}>