Skip to content

Commit

Permalink
feat(#138): accordion (#142)
Browse files Browse the repository at this point in the history
* chore(#138): accordion template

* chore(#138): update accordion and related

---------

Co-authored-by: Brian Gilbert <[email protected]>
  • Loading branch information
Decipher and BrianGilbert authored Feb 19, 2024
1 parent 5c0ceae commit 9af8a98
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 9 deletions.
38 changes: 38 additions & 0 deletions src/components/Accordion.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import CTAccordion from './Accordion.vue'

export default {
title: 'CivicTheme/Molecules/Accordion',
component: CTAccordion,
argTypes: {
theme: {
options: ['dark', 'light'],
control: 'select'
},
},
parameters: {
status: {
type: 'beta',
}
}
}

const Template = (args, { argTypes }) => {
return {
props: Object.keys(argTypes),
template: `<CTAccordion v-bind="$props" v-on="$props">
<template v-if="$props.default">{{ $props.default }}</template>
</CTAccordion>`,
}
}

export const Default = Template.bind({})
Default.storyName = 'Accordion'
Default.args = {
background: false,
expandAll: true,
panels: [
{ title: 'Accordion title 1', content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur harum magnam modi obcaecati vitae voluptatibus! Accusamus atque deleniti, distinctio esse facere, nam odio officiis omnis porro quibusdam quis repudiandae veritatis.', id: 0 },
{ title: 'Accordion title 2', content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur harum magnam modi obcaecati vitae voluptatibus! Accusamus atque deleniti, distinctio esse facere, nam odio officiis omnis porro quibusdam quis repudiandae veritatis.', id: 1 },
{ title: 'Accordion title 3', content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur harum magnam modi obcaecati vitae voluptatibus! Accusamus atque deleniti, distinctio esse facere, nam odio officiis omnis porro quibusdam quis repudiandae veritatis.', id: 2 },
]
}
79 changes: 79 additions & 0 deletions src/components/Accordion.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div
class="ct-accordion"
:class="{
[themeClass]: true,
'ct-accordion--with-background': background
}"
>
<div class="container">
<div class="row">
<div class="col-xxs-12">
<!-- Slot: Content Top -->
<div v-if="$slots['content_top']" class="ct-accordion__content-top">

Check warning on line 13 in src/components/Accordion.vue

View workflow job for this annotation

GitHub Actions / build (16.x)

'class' should be on a new line
{{ content_top }}
</div>

<div class="ct-accordion__content">
<ul class="ct-accordion__panels">
<CTCollapsible
v-for="(panel, delta) of panels"
:collapsed="!expandAll && !panel.expanded"
class="ct-accordion__panels__panel"
data-collapsible-duration="250"
data-collapsible-trigger-wide=""
:key="`panel-${delta}`"

Check warning on line 25 in src/components/Accordion.vue

View workflow job for this annotation

GitHub Actions / build (16.x)

Attribute ":key" should go before "data-collapsible-trigger-wide"
panel-class="ct-accordion__panels__panel__content"
tag="li"
>
<template #trigger>
<div class="ct-accordion__panels__panel__header">
<CTButton
class="ct-accordion__panels__panel__header__button"
data-collapsible-trigger=""
:text="panel.title"
/>
</div>
</template>

<CTParagraph class="ct-accordion__panels__panel__content__inner">
<slot name="panel" :panel="{ panel }">

Check warning on line 40 in src/components/Accordion.vue

View workflow job for this annotation

GitHub Actions / build (16.x)

':panel' should be on a new line
{{ panel.content }}
</slot>
</CTParagraph>
</CTCollapsible>
</ul>
</div>

<!-- Slot: Content Top -->
<div v-if="$slots['content_bottom']" class="ct-accordion__content-bottom">

Check warning on line 49 in src/components/Accordion.vue

View workflow job for this annotation

GitHub Actions / build (16.x)

'class' should be on a new line
{{ content_bottom }}
</div>
</div>
</div>
</div>
</div>
</template>

<script>
import ThemeMixin from '../mixins/theme'
export default {
mixins: [ThemeMixin],
props: {
background: {
type: Boolean,
default: false,
},
expandAll: {
type: Boolean,
default: false,
},
panels: {
type: Array,
default: () => ([])
}
}
}
</script>
9 changes: 6 additions & 3 deletions src/components/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
>
<CTIcon
v-if="icon && iconPosition === 'before'"
class="ct-button__icon"
:class="iconClass"
:size="iconSize"
:symbol="icon"
/>
Expand All @@ -27,11 +27,10 @@

<CTIcon
v-if="icon && iconPosition === 'after'"
class="ct-button__icon"
:class="iconClass"
:size="iconSize"
:symbol="icon"
/>

</component>
</template>

Expand All @@ -50,6 +49,10 @@ export default {
type: String,
default: undefined
},
iconClass: {
type: String,
default: 'ct-button__icon'
},
iconPosition: {
type: String,
default: 'after'
Expand Down
27 changes: 21 additions & 6 deletions src/components/Collapsible.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<template>
<div
<component :is="tag"
data-collapsible="1"
v-bind="{
'data-collapsible-collapsed': collapsed
}"
>
<div data-collapsible-trigger="" @click="onClick">
<slot name="trigger">{{ trigger }}</slot>
</div>
<div data-collapsible-panel="">
<slot name="trigger" :trigger="{ onClick, trigger, triggerClass }">
<div :class="triggerClass" data-collapsible-trigger="" @click="onClick">
{{ trigger }}
</div>
</slot>

<div :class="panelClass" data-collapsible-panel="">
<slot />
</div>
</div>
</component>
</template>

<script>
Expand All @@ -21,9 +24,21 @@ export default {
type: Boolean,
default: undefined
},
panelClass: {
type: String,
default: undefined
},
tag: {
type: String,
default: 'div'
},
trigger: {
type: String,
default: 'Click me'
},
triggerClass: {
type: String,
default: undefined
}
},
Expand Down

0 comments on commit 9af8a98

Please sign in to comment.