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 3 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
31 changes: 31 additions & 0 deletions src/components/organisms/UiList/UiList.stories.ts
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
IconInHeadingStoriesSource,
AnswerWithCheckboxStories,
AnswerWithCheckboxStoriesSource,
ListBoxStories,
ListBoxStoriesSource,
} from './stories';

type ListArgsType = ListProps;
Expand Down Expand Up @@ -429,3 +431,32 @@ AnswerWithRadio.args = {
},
})),
};
export const ListBox:ListStoryType = {
render(args, {
name, argTypes,
}) {
return {
name,
components: { ListBoxStories },
setup() {
const { attrs } = getAttrs(args, argTypes, name);
return { attrs };
},
template: '<ListBoxStories v-bind="{...attrs}"/>',
};
},
};
ListBox.parameters = { docs: { source: { code: ListBoxStoriesSource } } };
ListBox.args = {
items: items.map((item, index) => ({
...item,
tag: UiCheckbox,
icon: 'info',
value: item,
modelValue: index === 1 && [ item ],
textLabelAttrs: {
tag: 'div',
class: 'list-box__label',
},
})),
};
56 changes: 56 additions & 0 deletions src/components/organisms/UiList/UiList.vue
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,35 @@
</UiListItem>
</template>
</slot>
<template v-if="hasLoader">
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
<component
:is="loader"
:is-loading="isLoading"
v-bind="defaultProps.loaderAttrs"
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
>
<template #loader>
<!-- @slot Use this slot to replace loader. -->
<slot name="loader" />
</template>
<!-- @slot Use this slot to place content inside button. -->
<slot />
</component>
</template>
</component>
</template>

<script setup lang="ts">
import {
h,
computed,
ref,
watch,
type HTMLAttributes,
defineAsyncComponent,
useSlots,
} from 'vue';
import UiListItem, { type ListItemAttrsProps } from './_internal/UiListItem.vue';
import type { LoaderAttrsProps } from '../../molecules/UiLoader/UiLoader.vue';
import UiListItemContent from './_internal/UiListItemContent.vue';
import type {
DefineAttrsProps,
Expand All @@ -63,13 +83,36 @@ export interface ListProps {
* Use this props to pass list items.
*/
items?: ListItem[];
/**
* Use this props to set button into loading state.
*/
isLoading?: boolean;
/**
* Use this props to pass attrs for UiLoader.
*/
loaderAttrs?: LoaderAttrsProps;
}
export type ListAttrsProps<HTMLAttrs = HTMLAttributes> = DefineAttrsProps<ListProps, HTMLAttrs>;

const props = withDefaults(defineProps<ListProps>(), {
tag: 'ul',
items: () => ([]),
isLoading: false,
loaderAttrs: () => ({}),
});
const defaultProps = computed(() => ({
loaderAttrs: {
type: 'skeleton' as const,
'transition-type': 'show',
...props.loaderAttrs,
},
}));
const hasLoader = ref(props.isLoading);
watch(() => (props.isLoading), (isLoading) => {
if (isLoading && !hasLoader.value) {
hasLoader.value = true;
}
}, { once: true });
const itemsToRender = computed(() => (props.items
.map((item, index) => {
if (typeof item === 'string') {
Expand All @@ -83,6 +126,19 @@ const itemsToRender = computed(() => (props.items
name: item.name || `list-item-${index}`,
};
})));
const slots = useSlots();
const loader = computed(() => (
hasLoader.value
? defineAsyncComponent({
loader: () => import('../../molecules/UiLoader/UiLoader.vue'),
delay: 0,
loadingComponent: () => (slots.default
? h('slot', slots.default())
: null)
,
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
})
: null
));
</script>

<style lang="scss">
Expand Down
74 changes: 74 additions & 0 deletions src/components/organisms/UiList/stories/ListBox.vue
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<template>
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
<UiList
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Keyboard interaction doesn't work as expected. For example: moving by keyboard from one option to another should be available by key arrow up and arrow down, now is possible using Tab and Tab+shift.

Please check the sections Keyboard interaction and Aria and add changes to code

Copy link
Contributor

Choose a reason for hiding this comment

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

Please check this section in confluence and fix keyboard navigation:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I left a few more links with details on how to use ul role="listbox and an alternative way with select:
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role
https://www.w3.org/WAI/ARIA/apg/patterns/listbox/examples/listbox-rearrangeable/
I should help to implement the best solution 😍

v-bind="args"
class="list-box"
/>
<div class="search-dropdown-input-row">
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
<UiButton
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
class="search-dropdown-input-row__button ui-button--text"
@click="clickHandler"
>
<UiIcon
icon="plus"
class="ui-button__icon"
/>
<UiText class="search-dropdown-input-row__button">
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
Didn't find chronic condition?
</UiText>
</UiButton>
<UiText class="search-dropdown-input-row__text">
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
Add with your own words
</UiText>
</div>
</template>

<script setup lang="ts">
import {
computed,
useAttrs,
defineOptions,
} from 'vue';
import {
UiButton,
UiIcon,
UiList,
UiText,
} from '@infermedica/component-library';

defineOptions({ inheritAttrs: false });
export interface AddEmits {
(e:'add'): void;
}
const attrs = useAttrs();
const args = computed(() => (attrs));

const emit = defineEmits<AddEmits>();
const clickHandler = () => {
emit('add');
};
</script>

<style lang="scss">
.list-box {
&__label {
display: flex;
justify-content: space-between;
}
}
.search-dropdown-input-row {
padding: var(--space-12) var(--space-4);

&__button {
margin-inline: var(--space-8);
font: var(--font-body-1-thick);
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
}

&__text {
padding: var(--space-4) var(--space-12);
margin-inline: var(--space-32);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
</style>
2 changes: 2 additions & 0 deletions src/components/organisms/UiList/stories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export { default as IconInHeadingStories } from './IconInHeading.vue';
export { default as IconInHeadingStoriesSource } from './IconInHeading.vue?raw';
export { default as AnswerWithCheckboxStories } from './AnswerWithCheckbox.vue';
export { default as AnswerWithCheckboxStoriesSource } from './AnswerWithCheckbox.vue?raw';
export { default as ListBoxStories } from './ListBox.vue';
export { default as ListBoxStoriesSource } from './ListBox.vue?raw';
kubaszajna marked this conversation as resolved.
Show resolved Hide resolved
Loading