Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for args #13

Open
tobiasdiez opened this issue Nov 8, 2022 · 5 comments
Open

Add support for args #13

tobiasdiez opened this issue Nov 8, 2022 · 5 comments
Labels
type: enhancement Improving upon an existing feature

Comments

@tobiasdiez
Copy link
Owner

tobiasdiez commented Nov 8, 2022

Proposal:

<script setup>
import Button from './Button.vue'

const args = defineArgs({
  color: { control: 'color' },
})
</script>
<template>
  <Stories :initial-args="{ label: 'Button' }">
     <Story title="Primary" :inital-args="{ color: 'red' }">
        <Button v-bind="args" />
      </Story>
  </Stories>
</template>

The parameter to defineArgs is optional and is automatically mapped to argTypes in the default export.

Ideally, we can reuse the workarounds of storybookjs/storybook#13917 to have a working source code display, that shows the current state of the component.

@JoJk0
Copy link

JoJk0 commented Jul 18, 2023

@tobiasdiez any update on this? I love using .vue files instead of CSF but I've had to ditch it as lack of args customization is a show stopper for me 👎

@andreasvirkus
Copy link

Same as @JoJk0 above ☝️ 😞

@floroz
Copy link
Contributor

floroz commented Aug 15, 2023

Proposal:

<script setup>
import Button from './Button.vue'

const args = defineArgs({
  color: { control: 'color' },
})
</script>
<template>
  <Stories :initial-args="{ label: 'Button' }">
     <Story title="Primary" :inital-args="{ color: 'red' }">
        <Button v-bind="args" />
      </Story>
  </Stories>
</template>

The parameter to defineArgs is optional and is automatically mapped to argTypes in the default export.

Ideally, we can reuse the workarounds of storybookjs/storybook#13917 to have a working source code display, that shows the current state of the component.

In this example, you are binding v-bind="args" where args is referencing the scope of the script setup.

How is the :initial-args object mutating that?

I wonder if supporting args is necessary and brings more advantages than an additional syntax overhead to map 1:1 with the Storybook CSF.

Ultimately, instead of declaring a value on an object key, you declare a variable within the script context:

<script setup lang="ts">
import BButton from "./b-button.vue";

const shortLabel = 'Click';
const longLabel = 'Click me';
</script>

<template>
  <Stories title="Components/Button" :component="BButton">
    <Story title="ShortLabel">
      <BButton :label="shortLabel"/>
    </Story>
    <Story title="LongLabel">
      <BButton :label="longLabel" />
    </Story>
  </Stories>
</template>

Since you are passing the value directly to the component, you won't need the type inference since the value of shortLabel will be check for compatibility directly on the Component prop :label.

I am not sure I can see an immediate benefit of defineArgs when compared to this approach since it follows the natural Vue SFC logic?

However, there is definitely the need to have a defineArgTypes to customize the controls.

@tobiasdiez
Copy link
Owner Author

I agree for simple templates there is little advantages over having multiple story defs. But if the story template gets more involved, you don't want to copy-paste it to every variant of the args. But probably this use case can be taken care of by #1.

@tobiasdiez tobiasdiez added the type: enhancement Improving upon an existing feature label Sep 4, 2023
@floroz
Copy link
Contributor

floroz commented Sep 12, 2023

This could be closed and we could track the progress in #76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improving upon an existing feature
Projects
None yet
Development

No branches or pull requests

4 participants