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

Feature/storybook #157

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
coverage/
storybook-static/
.eslintcache
.DS_Store
dist/
Expand Down
7 changes: 6 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = {
stories: ['../stories/**/*.stories.{js,mdx}'],
stories: ['../stories/**/*.stories.{js,ts,mdx}'],
docs: {
//👇 See the table below for the list of supported options
autodocs: 'tag',
defaultName: 'Documentation',
},
};
284 changes: 177 additions & 107 deletions stories/cosmoz-autocomplete.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,118 +5,188 @@ import { colors } from './data';
export default {
title: 'Autocomplete',
component: 'cosmoz-autocomplete',
tags: ['autodocs'],
argTypes: {
label: { control: 'text' },
textProperty: { control: 'text' },
limit: { control: 'number' },
defaultIndex: { control: 'number' },
hideEmpty: { control: 'boolean' },
disabled: { control: 'boolean' },
placeholder: { control: 'text' },
showSingle: { control: 'boolean' },
preserveOrder: { control: 'boolean' },
min: { control: 'number' },
wrap: { control: 'boolean' },
},
};
const css = html`
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;300;400;500&display=swap');
cosmoz-autocomplete,
cosmoz-listbox {
font-family: 'Inter', sans-serif;
}
</style>
`,
basic = () => html`
${css}
<cosmoz-autocomplete
.label=${'Choose color'}
.source=${colors}
.textProperty=${'text'}
.value=${[colors[0], colors[3]]}
></cosmoz-autocomplete>
`,
single = () => html`
${css}
<cosmoz-autocomplete
.label=${'Choose color'}
.source=${colors}
.limit=${1}
.textProperty=${'text'}
.value=${colors[2]}
></cosmoz-autocomplete>
`,
hideEmpty = () => html`
${css}
<cosmoz-autocomplete
.label=${'Choose color'}
.source=${colors}
.limit=${1}
.textProperty=${'text'}
.value=${colors[2]}
hide-empty
></cosmoz-autocomplete>
`,
defaultIndex = () => html`
${css}
<cosmoz-autocomplete
.label=${'Choose color'}
.source=${colors}
.limit=${1}
.textProperty=${'text'}
default-index="-1"
></cosmoz-autocomplete>
<cosmoz-autocomplete
.label=${'Choose color (single value)'}
.source=${colors.slice(0, 1)}
.limit=${1}
.textProperty=${'text'}
default-index="-1"
></cosmoz-autocomplete>
`,
disabled = () => html`
${css}
<cosmoz-autocomplete
disabled
.label=${'Choose color'}
.source=${colors}
.limit=${1}
.textProperty=${'text'}
.value=${colors[2]}
></cosmoz-autocomplete>
`,
placeholder = () => html`
${css}
<cosmoz-autocomplete
.placeholder=${'Choose color'}
.source=${colors}
.limit=${1}
.textProperty=${'text'}
.value=${colors[0]}
></cosmoz-autocomplete>
`;

export { basic, single, hideEmpty, defaultIndex, disabled, placeholder };
const CSS = html`
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;300;400;500&display=swap');
cosmoz-autocomplete,
cosmoz-listbox {
font-family: 'Inter', sans-serif;
}
</style>
`;

const Autocomplete = ({
source,
limit,
textProperty,
min,
label = '',
value = [],
hideEmpty = false,
disabled = false,
placeholder = '',
defaultIndex = 0,
showSingle = false,
preserveOrder = false,
wrap = false,
}) => html`
${CSS}
<cosmoz-autocomplete
.label=${label}
.placeholder=${placeholder}
.source=${source}
.textProperty=${textProperty}
.limit=${limit}
.value=${value}
.hideEmpty=${hideEmpty}
.defaultIndex=${defaultIndex}
.disabled=${disabled}
.showSingle=${showSingle}
.preserveOrder=${preserveOrder}
.min=${min}
.wrap=${wrap}
></cosmoz-autocomplete>
`;

export const Basic = Autocomplete.bind({});
Basic.args = {
label: 'Choose color',
source: colors,
textProperty: 'text',
value: [colors[0], colors[3]],
};

export const Single = Autocomplete.bind({});
Single.args = {
label: 'Choose color',
source: colors,
textProperty: 'text',
limit: 1,
value: [colors[2]],
};

export const overflown = () =>
html` ${css}
<cosmoz-autocomplete
.label=${'Choose color'}
.source=${colors}
.textProperty=${'text'}
.value=${[colors[0], colors[1], colors[2]]}
style="max-width: 170px"
></cosmoz-autocomplete>`;
export const HideEmpty = Autocomplete.bind({});
HideEmpty.args = {
label: 'Choose color',
source: colors,
textProperty: 'text',
limit: 1,
value: [colors[2]],
hideEmpty: true,
};

export const wrap = () =>
html` ${css}
<cosmoz-autocomplete
.label=${'Choose color'}
.source=${colors}
.textProperty=${'text'}
.value=${[colors[0], colors[1], colors[2]]}
wrap
style="max-width: 170px"
></cosmoz-autocomplete>`;
export const DefaultIndex = Autocomplete.bind({});
DefaultIndex.args = {
label: 'Choose color',
source: colors,
textProperty: 'text',
limit: 1,
defaultIndex: -1,
};

export const select = () => html`
${css}
export const DefaultIndexSingleValue = Autocomplete.bind({});
DefaultIndexSingleValue.args = {
label: 'Choose color (single value)',
source: colors.slice(0, 1),
textProperty: 'text',
limit: 1,
defaultIndex: -1,
};

export const Disabled = Autocomplete.bind({});
Disabled.args = {
label: 'Choose color',
source: colors,
textProperty: 'text',
limit: 1,
value: colors[0],
disabled: true,
};

export const Placeholder = Autocomplete.bind({});
Placeholder.args = {
placeholder: 'Choose color (placeholder text)',
source: colors,
limit: 1,
textProperty: 'text',
value: colors[0],
};

export const Select = Autocomplete.bind({});
Select.args = {
label: 'Choose color',
source: colors,
limit: 1,
textProperty: 'text',
value: colors[2],
showSingle: true,
preserveOrder: true,
min: 1,
};

const AutocompleteWithInlineCSS = ({
source,
limit,
textProperty,
min,
label = '',
value = [],
hideEmpty = false,
disabled = false,
placeholder = '',
defaultIndex = 0,
showSingle = false,
preserveOrder = false,
wrap = false,
}) => html`
${CSS}
<cosmoz-autocomplete
.label=${'Choose color'}
.source=${colors}
.limit=${1}
.textProperty=${'text'}
.value=${colors[2]}
show-single
preserve-order
.min=${1}
.label=${label}
.placeholder=${placeholder}
.source=${source}
.textProperty=${textProperty}
.limit=${limit}
.value=${value}
.hideEmpty=${hideEmpty}
.defaultIndex=${defaultIndex}
.disabled=${disabled}
.showSingle=${showSingle}
.preserveOrder=${preserveOrder}
.min=${min}
.wrap=${wrap}
style="max-width: 170px"
></cosmoz-autocomplete>
`;

export const Overflown = AutocompleteWithInlineCSS.bind({});
Overflown.args = {
label: 'Choose color',
source: colors,
textProperty: 'text',
value: [colors[0], colors[1], colors[2]],
};

export const Wrap = AutocompleteWithInlineCSS.bind({});
Wrap.args = {
label: 'Choose color',
source: colors,
textProperty: 'text',
value: [colors[0], colors[1], colors[2]],
wrap: true,
};
4 changes: 2 additions & 2 deletions stories/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const colors = [
'White',
'Brown',
'Aqua',
'Nothing'
].map(text => ({ text }));
'Nothing',
].map((text) => ({ text }));

export { colors };
Loading