-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
1,875 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/vue/src/components/BaseAccordionItem/BaseAccordionItem.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import BaseAccordionItem from './BaseAccordionItem.vue' | ||
import { BlockStreamfieldTruncatedData } from '../BlockStreamfield/BlockStreamfield.stories' | ||
export default { | ||
title: 'Components/Base/BaseAccordionItem', | ||
component: BaseAccordionItem | ||
} | ||
|
||
// stories | ||
export const BaseStory = { | ||
name: 'BaseAccordionItem', | ||
args: { | ||
headingLevel: 'h3', | ||
item: { title: 'Title for the accordion', body: BlockStreamfieldTruncatedData.body } | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
packages/vue/src/components/BaseAccordionItem/BaseAccordionItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<script setup lang="ts"> | ||
import { computed, reactive, ref } from 'vue' | ||
import { AccordionItemObject } from './../../interfaces.ts' | ||
import { uniqueId } from 'lodash' | ||
import IconPlus from './../Icons/IconPlus.vue' | ||
import BlockStreamfield from './../BlockStreamfield/BlockStreamfield.vue' | ||
export interface BaseAccordionItemProps { | ||
headingLevel?: string | ||
item: AccordionItemObject | ||
backgroundClass?: string | ||
} | ||
// define props | ||
const props = withDefaults(defineProps<BaseAccordionItemProps>(), { | ||
headingLevel: 'h2', | ||
backgroundClass: undefined, | ||
item(): AccordionItemObject { | ||
return { | ||
title: undefined, | ||
body: undefined | ||
} | ||
} | ||
}) | ||
const { headingLevel, item } = reactive(props) | ||
const ariaExpanded = ref(false) | ||
const isHidden = ref(true) | ||
const itemId = ref(uniqueId()) | ||
const panelId = computed(() => { | ||
return `block_accordion_panel_${itemId.value}` | ||
}) | ||
const headingId = computed(() => { | ||
return `block_accordion_heading_${itemId.value}` | ||
}) | ||
const handleClick = () => { | ||
ariaExpanded.value = !ariaExpanded.value | ||
isHidden.value = !isHidden.value | ||
if (isHidden.value) { | ||
emit('accordionItemClosed') | ||
} else { | ||
emit('accordionItemOpened') | ||
} | ||
} | ||
const emit = defineEmits(['accordionItemOpened', 'accordionItemClosed']) | ||
</script> | ||
<template> | ||
<div | ||
class="BaseAccordionItem" | ||
:class="{ '-open': !isHidden }" | ||
> | ||
<div class="BaseAccordionHeader"> | ||
<slot name="header"> | ||
<div | ||
v-if="headingLevel && item" | ||
class="border-b border-gray-light-mid" | ||
> | ||
<component :is="headingLevel"> | ||
<button | ||
v-bind-once="{ id: headingId, 'aria-controls': panelId }" | ||
:aria-expanded="ariaExpanded" | ||
class="BaseAccordion-trigger group flex flex-nowrap justify-between items-center w-full can-hover:hover:underline text-body-lg" | ||
@click="handleClick()" | ||
> | ||
<slot name="heading"> | ||
<div class="pointer-events-none text-left p-4 xl:py-6"> | ||
{{ item.title }} | ||
</div> | ||
</slot> | ||
<span | ||
class="BaseAccordion-icon pointer-events-none text-xs text-action flex-shrink-0 transform transition-transform" | ||
:class="{ 'rotate-45': !isHidden }" | ||
> | ||
<IconPlus /> | ||
</span> | ||
</button> | ||
</component> | ||
</div> | ||
</slot> | ||
</div> | ||
<div | ||
v-show="!isHidden" | ||
class="BaseAccordionContent" | ||
> | ||
<slot> | ||
<div | ||
v-bind-once="{ id: panelId, 'aria-labelledby': headingId }" | ||
role="region" | ||
class="BaseAccordion-panel" | ||
> | ||
<slot name="panelContents"> | ||
<div class="px-4 pb-8"> | ||
<BlockStreamfield | ||
:data="item.body" | ||
variant="fluid" | ||
/> | ||
</div> | ||
</slot> | ||
</div> | ||
</slot> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/vue/src/components/BlockAccordion/BlockAccordion.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import BlockAccordion from './BlockAccordion.vue' | ||
import { BlockStreamfieldTruncatedData } from '../BlockStreamfield/BlockStreamfield.stories' | ||
|
||
export default { | ||
title: 'Components/Blocks/BlockAccordion', | ||
component: BlockAccordion | ||
} | ||
|
||
// stories | ||
export const BaseStory = { | ||
name: 'BlockAccordion', | ||
args: { | ||
headingLevel: 'h5', | ||
items: [ | ||
{ | ||
title: 'Title for the accordion', | ||
body: BlockStreamfieldTruncatedData.body | ||
}, | ||
{ | ||
title: 'Another', | ||
body: BlockStreamfieldTruncatedData.body | ||
}, | ||
{ | ||
title: 'Yet another', | ||
body: BlockStreamfieldTruncatedData.body | ||
} | ||
] | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/vue/src/components/BlockAccordion/BlockAccordion.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script setup lang="ts"> | ||
import { reactive } from 'vue' | ||
import { AccordionItemObject } from '../../interfaces' | ||
import BaseAccordionItem from './../BaseAccordionItem/BaseAccordionItem.vue' | ||
interface BlockAccordionProps { | ||
autoClose?: boolean | ||
headingLevel?: string | ||
items?: AccordionItemObject[] | ||
} | ||
// define props | ||
const props = withDefaults(defineProps<BlockAccordionProps>(), { | ||
autoClose: false, | ||
headingLevel: 'h2', | ||
items: undefined | ||
}) | ||
const { headingLevel, items } = reactive(props) | ||
</script> | ||
<template> | ||
<div class="BlockAccordion"> | ||
<slot> | ||
<BaseAccordionItem | ||
v-for="(item, index) in items" | ||
:key="index" | ||
:heading-level="headingLevel" | ||
:item="item" | ||
/> | ||
</slot> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.