Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</script>

<!-- More on writing stories with args: https://storybook.js.org/docs/writing-stories/args -->
<Story name="Primary" args={{ primary: true, label: 'Button' }} />
<Story name="Primary" args={{ variant: 'primary', label: 'Button' }} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Verify that Button.svelte component accepts 'variant' prop, as this was changed from 'primary' without corresponding component changes visible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were component changes. Try not to hallucinate please.


<Story name="Secondary" args={{ label: 'Button' }} />
<Story name="Secondary" args={{ variant: 'secondary', label: 'Button' }} />

<Story name="Large" args={{ size: 'large', label: 'Button' }} />

Expand Down
27 changes: 22 additions & 5 deletions code/frameworks/sveltekit/template/cli/ts/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import './button.css';

interface Props {
/** Is this the principal call to action on the page? */
primary?: boolean;
/**
* The variant of the button
*
* @default primary
*/
variant?: 'primary' | 'secondary' | 'flat';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding @default 'primary' in the JSDoc since there's a default value in the code

/** What background color to use */
backgroundColor?: string;
/** How large should the button be? */
Expand All @@ -14,9 +18,22 @@
onclick?: () => void;
}

const { primary = false, backgroundColor, size = 'medium', label, ...props }: Props = $props();

let mode = $derived(primary ? 'storybook-button--primary' : 'storybook-button--secondary');
const {
variant = 'primary',
backgroundColor,
size = 'medium',
label,
...props
}: Props = $props();

const variantToClass = {
primary: 'storybook-button--primary',
secondary: 'storybook-button--secondary',
// Flat only exists to verify type inference for the control creation works
flat: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Empty string for 'flat' variant might be unclear - consider adding a comment explaining why flat variant has no class

};

let mode = $derived(variantToClass[variant]);
let style = $derived(backgroundColor ? `background-color: ${backgroundColor}` : '');
</script>

Expand Down
1 change: 0 additions & 1 deletion code/renderers/svelte/src/extractArgTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ const parseTypeToControl = (type: JSDocType | undefined): any => {
return {
control: {
type: 'radio',
labels: options.map(String),
},
options,
};
Expand Down