Improve storybook story selection (#3653)
This PR builds on top of #3652 by adding a selection prompt to the storybook to allow you to choose from the available list of stories if you don't provide one explicitly: <img width="1387" alt="Screenshot 2023-12-14 at 12 00 26 PM" src="https://github.com/zed-industries/zed/assets/1486634/640d62a3-1340-45f1-9746-69b513faff62"> This way we don't have to keep generating the `script/storybook` script whenever stories are added/removed. #### Usage (through `cargo`): ```sh # Select from the available stories cargo run -p storybook2 # Run a specific story cargo run -p storybook2 -- components/list_item ``` #### Usage (through `script/storybook`): ```sh # Select from the available stories ./script/storybook # Run a specific story ./script/storybook list_item ``` Release Notes: - N/A
This commit is contained in:
parent
08418618ab
commit
fd133df896
6 changed files with 107 additions and 169 deletions
|
@ -1,60 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
options=(
|
||||
"auto_height_editor"
|
||||
"avatar"
|
||||
"button"
|
||||
"checkbox"
|
||||
"context_menu"
|
||||
"cursor"
|
||||
"disclosure"
|
||||
"focus"
|
||||
"icon"
|
||||
"icon_button"
|
||||
"keybinding"
|
||||
"label"
|
||||
"list"
|
||||
"list_header"
|
||||
"list_item"
|
||||
"overflow_scroll"
|
||||
"scroll"
|
||||
"tab"
|
||||
"tab_bar"
|
||||
"text"
|
||||
"viewport_units"
|
||||
"z_index"
|
||||
"picker"
|
||||
)
|
||||
|
||||
run_story() {
|
||||
echo "Running story: $1"
|
||||
cargo run -p storybook2 -- "$1"
|
||||
}
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
story_arg="$1"
|
||||
# Add prefix 'components/' if not present
|
||||
if [[ $story_arg != components/* ]]; then
|
||||
story_arg="components/$story_arg"
|
||||
fi
|
||||
# Check if the provided story is a valid option
|
||||
for opt in "${options[@]}"; do
|
||||
if [[ "components/$opt" == "$story_arg" ]]; then
|
||||
run_story "$story_arg"
|
||||
exit
|
||||
fi
|
||||
done
|
||||
echo "Invalid story name: $1"
|
||||
exit 1
|
||||
if [ -z "$1" ]; then
|
||||
cargo run -p storybook2
|
||||
else
|
||||
cargo run -p storybook2 -- "components/$1"
|
||||
fi
|
||||
|
||||
prompt="Please select a story:"
|
||||
PS3="$prompt "
|
||||
select story in "${options[@]}"; do
|
||||
if [[ -n $story ]]; then
|
||||
run_story "components/$story"
|
||||
break
|
||||
else
|
||||
echo "Invalid option"
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue