Skip to content

Commit

Permalink
fix: v-model issue in UiHorizontalPaging stories (#493)
Browse files Browse the repository at this point in the history
* fix: remove quote's from getArgTypes props default values

* fix: aliased import in UiMenu

* fix: v-model issue in UiHorizontalPaging stories

* feat: add useArgs composable
  • Loading branch information
pspaczek committed May 29, 2024
1 parent efa6c4f commit 0f4e6af
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
21 changes: 21 additions & 0 deletions .storybook/composable/useArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
computed,
useAttrs,
} from "vue";

export function useArgs(excludedAttrs:string[] = []) {
const attrs = useAttrs();
const args = computed(() => (Object.keys(attrs).reduce((object, key) => {
if (!excludedAttrs.includes(key)) {
return {
...object,
[key]: attrs[key],
};
}
return object;
}, {})));
return {
attrs,
args
}
}
5 changes: 4 additions & 1 deletion .storybook/decorators/withVModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ref,
computed,
defineComponent,
provide,
Expand All @@ -13,9 +14,11 @@ export const withVModel = (story, { id, args }) => {
name: 'DWithVModel',
inheritAttrs: false,
setup() {
const modelValueFallback = ref(null)
const modelValue = computed({
get: ()=>(args.modelValue),
get: ()=>(modelValueFallback.value || args.modelValue),
set: (newValue) => {
modelValueFallback.value = newValue;
updateArgs({ modelValue: newValue });
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ref="horizontalPagingTemplateRefs"
v-model="value"
v-bind="args"
:menu-template-refs="menuTemplateRef"
:menu-template-ref="menuTemplateRef"
>
<template
#menu="{
Expand Down Expand Up @@ -78,7 +78,6 @@
import {
ref,
computed,
useAttrs,
defineOptions,
inject,
nextTick,
Expand All @@ -93,15 +92,18 @@ import {
UiLink,
UiHeading,
} from '@infermedica/component-library';
import { useArgs } from '@sb/composable/useArgs';
import MedicalCertification from './_internal/MedicalCertification.vue';
import TermsOfService from './_internal/TermsOfService.vue';
import InterviewId from './_internal/InterviewId.vue';
import { focusElement } from '../../../../utilities/helpers';
defineOptions({ inheritAttrs: false });
const attrs = useAttrs();
const args = computed(() => (attrs));
const value = inject('value', []);
const {
attrs,
args,
} = useArgs([ 'modelValue' ]);
const value = inject('value', ref([]));
const horizontalPagingTemplateRefs = ref(null);
const isActive = computed(() => (horizontalPagingTemplateRefs.value?.isActive));
Expand Down
19 changes: 7 additions & 12 deletions src/components/organisms/UiHorizontalPaging/stories/Multilevel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,22 @@

<script setup lang="ts">
import {
computed,
useAttrs,
defineOptions,
inject,
} from 'vue';
import {
UiHorizontalPaging,
UiLoader,
} from '@infermedica/component-library';
import { useArgs } from '@sb/composable/useArgs';
defineOptions({ inheritAttrs: false });
const attrs = useAttrs();
const args = computed(() => (Object.keys(attrs).reduce((object, key) => {
if (key !== 'items') {
return {
...object,
[key]: attrs[key],
};
}
return object;
}, {})));
const {
attrs, args,
} = useArgs([
'modelValue',
'items',
]);
const value = inject('value', []);
const itemsA = [
{
Expand Down

0 comments on commit 0f4e6af

Please sign in to comment.