Skip to content

Add Storybook support #55

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

Closed
wants to merge 13 commits into from
Closed

Conversation

kentookura
Copy link

@kentookura kentookura commented Dec 23, 2022

When using ui-core as a dependency for a storybook, vite does not load the styles unless all import declarations are on top.

When using ui-core as a dependency for a storybook, vite complains about when imports are not on top of the file.
@kentookura kentookura changed the title Move imports to top of file Add Storybook support Dec 23, 2022
@yoching
Copy link
Contributor

yoching commented Dec 23, 2022

I’m not sure if it’s a good idea to put these into ui-core repository, as it will make dependency management complicated, especially because it introduces vite. I think it’s better to keep ui-core as simple as possible, preferably keeping the dependency only on Elm things.
Also, the storybook implementation is in its very early stage, I think it's too early to integrate here. A bit more exploration, such as adding more complicated components, will be necessary before deciding how to integrate it well.

@yoching
Copy link
Contributor

yoching commented Dec 23, 2022

On the other hand, it would be nice to merge the change in ui.css (moving @imports to the top of the file), if it doesn't break any other parts of the UI.

@kentookura
Copy link
Author

I moved all the storybook stuff into its own directory with separate elm.json and package.json files. Vite is now a dependency for running storybook but since we use elm-git, we can use ui-core in local-ui without vite and storybook.

My code formatter reformatted elm.json but no real changes were made. Should we agree on a common formatting config for the javascript stuff?

// Automatically creates stories from .elm files
config.plugins.push(StorybookElmPlugin());
return mergeConfig(config, {
server: { fs: { allow: [".."] } },
Copy link
Author

Choose a reason for hiding this comment

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

This allows vite to load the required fonts. Any further configuration to the build process goes here

{
"type": "application",
"source-directories": [
"../src",
Copy link
Author

Choose a reason for hiding this comment

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

Allows us to use ui-core without elm-git

Copy link
Contributor

@yoching yoching left a comment

Choose a reason for hiding this comment

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

It seems that components in elm-storybook directory are not used. What are those for?

stateless options =
Browser.element
{ init = \() -> ( (), Cmd.none )
, update = \msg model -> ( model, Cmd.none )
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's nice to keep logAction here so that actions appear on the storybook UI.
https://github.com/yoching/unison-ui-core-storybook/blob/main/src/Storybook/Story.elm#L18

Copy link
Author

Choose a reason for hiding this comment

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

I added it again. I needed to add the keyword port to the module declaration to make it work

sandbox options =
Browser.element
{ init = \() -> ( options.init, Cmd.none )
, update = \msg model -> ( options.update msg model, Cmd.none )
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Copy link
Member

@hojberg hojberg left a comment

Choose a reason for hiding this comment

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

Sorry for being super slow on this. Really awesome work! 🎉

Would it be possible to use webpack instead of vite here? We use webpack everywhere else, and I'm not sure I'm ready to take to time to switch.

},
"test-dependencies": {
"elm-explorations/test": "1.2.0 <= v < 2.0.0"
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we "unformat" this file? Elm manages it and will re-format on the next elm install I believe, which will add a bit of commit noise

@import "./ui/animations.css";
@import "./ui/components.css";
@import "./ui/page-layout.css";

Copy link
Member

Choose a reason for hiding this comment

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

See #57

paramKey: "elm-source",
render: ({ active, key }) => {
return (active)
? React.createElement(StoryPanel, { className: "banana", key, api }, null)
Copy link
Member

Choose a reason for hiding this comment

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

whats "banana" for?

Copy link
Author

Choose a reason for hiding this comment

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

This comes from here

Copy link
Author

Choose a reason for hiding this comment

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

I'll have a closer look at what parts of the code are holdovers from the example

}
}
}
})
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to run prettier on the js files.


col : List (Attribute msg) -> List (Html msg) -> Html msg
col attrs children =
Html.div (Html.Attributes.class "col" :: attrs) children
Copy link
Member

Choose a reason for hiding this comment

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

I think this is useful enough to be added to either a new UI.Layout module or just as a function on the UI module.

@kentookura
Copy link
Author

It's certainly possible. The example we used as reference uses the vite builder for storybook, see here
I'll try to get it to work with the webpack builder

@yoching
Copy link
Contributor

yoching commented Jan 31, 2023

I tried webpack first but didn't find a way to make it work.

@hojberg
Copy link
Member

hojberg commented Mar 27, 2023

Closing this since we got the webpack version merged. Thank you so much both!

@hojberg hojberg closed this Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants