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

docs: add stories for UiMenu #489

Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8b57510
feat: implement ListBox for MultiSelect lists
kubaszajna May 15, 2024
bdacf39
feat: additional button for ListBox
kubaszajna May 15, 2024
79c3648
feat: loader for ListBox
kubaszajna May 28, 2024
2f3dd4b
feat: styles and template update
kubaszajna Jun 6, 2024
7870d8e
feat: refactor list box element with button
kubaszajna Jun 7, 2024
85c7bb2
fix: vue types updated
kubaszajna Jun 12, 2024
4024dfd
feat: new loader and styling
kubaszajna Jul 2, 2024
b61f2e9
fix: update emit definition
kubaszajna Jul 2, 2024
0ec29bf
fix: implement changes after review
kubaszajna Jul 5, 2024
7434030
Merge remote-tracking branch 'upstream/develop' into feat/implement-l…
kubaszajna Jul 5, 2024
310ff7b
fix: changes after review
kubaszajna Jul 11, 2024
a2785ae
feat: add story with new list to menu organism
kubaszajna Jul 19, 2024
9578d49
fix: delete unused elements from uilist
kubaszajna Jul 22, 2024
fe3c34d
feat: implement styles and checkboxes
kubaszajna Jul 23, 2024
182807d
Merge remote-tracking branch 'upstream/develop' into feat/implement-l…
kubaszajna Jul 23, 2024
7591e2c
fix: update aria attributes
kubaszajna Jul 23, 2024
7feb229
fix: styles for button under list
kubaszajna Jul 23, 2024
449a823
feat: aria-label added
kubaszajna Jul 23, 2024
6303e8c
Merge branch 'develop' into feat/implement-listbox-for-multiselect-lists
pspaczek Jul 24, 2024
c101227
feat: update has button story
kubaszajna Jul 25, 2024
cb31511
fix: refactor after review
kubaszajna Jul 25, 2024
242edb3
feat: refactor has button and styles
kubaszajna Jul 26, 2024
9ae5a58
fix: refactor after review
kubaszajna Jul 26, 2024
3f33a2a
feat: refactor hasbutton
kubaszajna Jul 29, 2024
293e915
feat: update has button stories
kubaszajna Jul 29, 2024
6c2601f
feat: refactor template and styles
kubaszajna Jul 29, 2024
b261f02
refactor: add improvements to existing code
pspaczek Jul 29, 2024
817f11a
Merge branch 'feat/implement-listbox-for-multiselect-lists' of https:…
kubaszajna Jul 30, 2024
d6de3c6
feat: refactor styles and enter handler
kubaszajna Jul 30, 2024
8af656e
fix: aria-label added
kubaszajna Jul 30, 2024
51bb198
fix: delete console log
kubaszajna Jul 30, 2024
0adb443
feat: delete unused elements
kubaszajna Jul 30, 2024
dbacf40
fix: update hasbutton key handler
kubaszajna Jul 30, 2024
2ce8201
feat: add aria-activedescendant and styles
kubaszajna Jul 31, 2024
b7107f3
refactor: add improvements to existing code
pspaczek Jul 31, 2024
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
47 changes: 47 additions & 0 deletions src/components/organisms/UiMenu/UiMenu.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
BasicStoriesSource,
ItemsViaSlotStories,
HasOutsideElementsStories,
HasButtonStories,
HasButtonStoriesSource,
} from './stories';
import { withVModel } from '../../../../.storybook/decorators';

type MenuArgsType = MenuProps;
type MenuMetaType = Meta<MenuArgsType>;
Expand All @@ -42,6 +45,10 @@ const meta = {
title: 'Organisms/Menu',
component: UiMenu,
args: {
translation: {
label: 'Didn\'t find chronic condition?',
hint: 'Add with your own words',
},
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
...metaArgs,
items,
},
Expand Down Expand Up @@ -139,4 +146,44 @@ export const HasOutsideElements: MenuStoryType = {
};
},
};
export const HasButton:MenuStoryType = {
render(args, {
name, argTypes,
}) {
return {
name,
components: { HasButtonStories },
setup() {
const { attrs } = getAttrs(args, argTypes, name);

return { attrs };
},
template: `
<HasButtonStories v-bind="{...attrs}" :translation="translation"/>
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
`,
};
},
};
HasButton.args = {
modelValue: [ 'ADHD — hyperactive type' ],
items: [
'ADHD — hyperactive type',
'ADHD — inattentive type',
'Abdominal aortic aneurysm',
'Achalasia',
'Acne',
'Acoustic neuroma',
'Painful swallowing',
'Stuffy nose',
'Sneeze',
'Muscle pain',
'Runny nose',
'Wernicke`s encephalopathy',
'Whipworm infection',
'Wilson`s disease',
'Zollinger-Ellison syndrome',
],
};
HasButton.decorators = [ withVModel ];
HasButton.parameters = { docs: { source: { code: HasButtonStoriesSource } } };

8 changes: 7 additions & 1 deletion src/components/organisms/UiMenu/UiMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
v-bind="item"
:name="item.name"
>
<UiText>{{ item.label }}</UiText>
<UiText tag="span">
{{ item.label }}
</UiText>
</slot>
</UiMenuItem>
</template>
Expand Down Expand Up @@ -224,4 +226,8 @@ defineExpose({
}
}
}

div:has(.has-button) {
max-width: none !important; // overwriting styles from template
}
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
</style>
164 changes: 164 additions & 0 deletions src/components/organisms/UiMenu/stories/HasButton.vue
pspaczek marked this conversation as resolved.
Show resolved Hide resolved
pspaczek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<template>
<UiPopover class="has-button">
<UiMenu
v-bind="args"
:items="itemsToRender"
role="listbox"
aria-label="Chronic condition"
aria-multiselectable="true"
aria-activedescendant=""
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
:aria-busy="!allPredefinedOptionsAreLoaded"
>
<template
v-for="({
label, name, checkboxAttrs,
}, index) in itemsToRender"
#[`menu-item-${index}`]
:key="name"
>
<UiCheckbox v-bind="checkboxAttrs" :aria-label="label">
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
{{ label }}
</UiCheckbox>
</template>
<template #custom-option @keyup.enter="handleCustomOptionClick">
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
<UiIcon
icon="plus"
class="ui-button__icon has-button__custom-option-icon"
/>
<UiText
tag="span"
class="ui-text--body-1-thick"
>
Didn't find chronic condition?
</UiText>
<UiText
tag="span"
class="has-button__custom-option-hint"
>
Add with your own words
</UiText>
</template>
</UiMenu>
</UiPopover>
</template>

<script setup lang="ts">
import {
computed,
useAttrs,
defineOptions,
onMounted,
ref,
inject,
} from 'vue';
import {
UiCheckbox,
UiIcon,
UiMenu,
UiPopover,
UiText,
} from '@infermedica/component-library';
import { equal } from '../../../../utilities/helpers';

defineOptions({ inheritAttrs: false });
const attrs = useAttrs();
const args = computed(() => (Object.keys(attrs).reduce((object, key) => {
if (key !== 'items') {
return {
...object,
[key]: args[key],
};
}
return object;
}, {})));

const value = inject('value', []);
const allPredefinedOptionsAreLoaded = ref(false);
onMounted(() => {
setTimeout(() => {
allPredefinedOptionsAreLoaded.value = true;
}, 1000);
});

const handleUpdateModelValue = (val) => (value['value'].includes(val)
? value['value'].filter((option) => (!equal(val, option)))
: [
...value['value'],
val,
]);
const handleOptionClick = (val) => {
value['value'] = handleUpdateModelValue(val);
};
const handleCustomOptionClick = () => {
console.log('emit cusomOtptionClick');
};
const itemsToRender = computed(() => {
const customOption = {
name: 'custom-option',
class: 'has-button__custom-option',
listItemAttrs: { class: 'ui-list-item ui-menu-item has-button__menu-item--has-border' },
onClick: () => handleCustomOptionClick(),
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
};
const items = (attrs.items as any).map((item) => ({
label: item,
checkboxAttrs: {
modelValue: value['value'],
value: item,
disabled: true,
},
onClick: () => handleOptionClick(item),
}));
return [
...items,
(
allPredefinedOptionsAreLoaded.value
? customOption
: {}
),
].map((item, index) => ({
...item,
'aria-selected': false,
'aria-setsize': items.length + (
allPredefinedOptionsAreLoaded.value
? 1
: 0
),
'aria-posinet': index + 1,
}));
});
</script>

<style lang="scss">
@use "../../../../styles/mixins";
.has-button {
--popover-content-padding-block: 0;
--popover-content-padding-inline: 0;

max-height: 20rem;
overflow-y: auto;

&__menu-item {
&--has-border {
border: 1px solid var(--color-border-divider);
border-width: 1px 0 0 0 ;
}
}

&__custom-option {
display: grid;
grid-template-columns: auto 1fr;
grid-template-rows: auto auto;
text-align: start;
gap: 0 var(--space-12);

&-icon {
--button-icon-margin-inline: 0;
--button-icon-margin-block: 0;
}

&-hint {
grid-column: 2;
}
}
}
</style>
2 changes: 2 additions & 0 deletions src/components/organisms/UiMenu/stories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export { default as ItemsViaSlotStories } from './ItemsViaSlot.vue';
export { default as ItemsViaSlotStoriesSource } from './ItemsViaSlot.vue?raw';
export { default as HasOutsideElementsStories } from './HasOutsideElements.vue';
export { default as HasOutsideElementsStoriesSource } from './HasOutsideElements.vue?raw';
export { default as HasButtonStories } from './HasButton.vue';
export { default as HasButtonStoriesSource } from './HasButton.vue?raw';
Loading