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

Added story to Dropdown #382

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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
64 changes: 64 additions & 0 deletions packages/alto/src/components/Dropdown/Dropdown.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { Meta, StoryObj } from '@storybook/vue3';
import { ref } from 'vue';
import { Dropdown } from '~/components';
import type { DropdownValue } from '~/types';

type Story = StoryObj<typeof Dropdown>;
const meta: Meta<typeof Dropdown> = {
title: 'Application/Dropdowns/Dropdown',
component: Dropdown,
tags: ['dropdown', 'select', 'option', 'options'],
argTypes: {
modelValue: { table: { disable: true } },
items: { table: { disable: true } },
item: { table: { disable: true } },
search: { table: { disable: true } },
clearable: {
if: { arg: 'multiple', truthy: false },
},
selectedItemsLabel: {
if: { arg: 'multiple', truthy: true },
},
limit: {
if: { arg: 'multiple', truthy: true },
},
searchInputPlaceholder: {
if: { arg: 'searchable', truthy: true },
},
},
args: {
placeholder: 'Select item',
disabled: false,
clearable: false,
multiple: false,
selectedItemsLabel: 'Selected items',
limit: 0,
emptyStateMessage: 'No results were found',
searchable: false,
searchInputPlaceholder: 'Search',
isLoading: false,
},
};

export const Default: Story = {
render: args => ({
components: { Dropdown },
setup() {
const items: Array<DropdownValue> = [
{ label: 'Arabic', key: 1 },
{ label: 'English', key: 2 },
{ label: 'German', key: 3 },
{ label: 'French', key: 4 },
{ label: 'Dutch', key: 5 },
{ label: 'Hindi', key: 6 },
];

const value = ref(null);

return { args, items, value };
},
template: '<Dropdown v-model="value" v-bind="args" :items="items" />',
}),
};

export default meta;
10 changes: 5 additions & 5 deletions packages/alto/src/components/Dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { setPosition } from '~/helpers';
import { Loader } from '~/components';

const props = withDefaults(defineProps<DropdownProps>(), {
multiSelectLabel: 'Selected items',
noDataText: 'No results were found',
selectedItemsLabel: 'Selected items',
emptyStateMessage: 'No results were found',
clearable: true,
limit: 0,
searchInputPlaceholder: 'Search',
Expand All @@ -37,14 +37,14 @@ function asArray() {
}

const selectedOptions = computed(() => {
const { modelValue, placeholder, multiple, multiSelectLabel } = props;
const { modelValue, placeholder, multiple, selectedItemsLabel } = props;
if (modelValue) {
if (!multiple) {
return (modelValue as DropdownValue).label;
}

if (multiple && asArray().length) {
return multiSelectLabel;
return selectedItemsLabel;
}
}

Expand Down Expand Up @@ -339,7 +339,7 @@ onClickOutside(dropdown, () => show.value = false);
</div>

<div v-else class="no-results">
{{ noDataText }}
{{ emptyStateMessage }}
</div>
<div v-if="isLoading" class="loading">
<Loader :size="15" />
Expand Down
4 changes: 2 additions & 2 deletions packages/alto/src/components/Dropdown/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export interface DropdownProps extends DropdownCommonProps {
placeholder?: string
multiple?: boolean
disabled?: boolean
multiSelectLabel?: string
selectedItemsLabel?: string
clearable?: boolean
noDataText?: string
emptyStateMessage?: string
limit?: number
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/vue3';
import { ref } from 'vue';
import { Status } from '~/components';
import type { StatusObject } from '~/components/Status/types';
import type { StatusObject } from '~/types';

type Story = StoryObj<typeof Status>;
const meta: Meta<typeof Status> = {
Expand Down
Loading