Skip to content

Commit

Permalink
feat(#106): add collapsible component
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Sep 4, 2023
1 parent e1d1aed commit 89949d3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/Collapsible.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import CTCollapsible from './Collapsible.vue'

export default {
title: 'CivicTheme/Base/Collapsible',
component: CTCollapsible,
parameters: {
status: {
type: 'beta',
}
}
}

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

export const Default = Template.bind({})
Default.storyName = 'Collapsible'
Default.args = {
default: 'Collapsible demo panel 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.',
trigger: 'TRIGGER (click me)'
}
47 changes: 47 additions & 0 deletions src/components/Collapsible.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<div
data-collapsible="1"
v-bind="{
'data-collapsible-collapsed': collapsed
}"
>
<div data-collapsible-trigger="">
<slot name="trigger">{{ trigger }}</slot>
</div>
<div data-collapsible-panel="">
<slot />
</div>
</div>
</template>

<script>
export default {
props: {
collapsed: {
type: Boolean,
default: undefined
},
trigger: {
type: String,
default: 'Click me'
}
},
mounted() {
try {
if (this.$el) {
delete require.cache[require.resolve('civictheme/components/00-base/collapsible/collapsible')]
require('civictheme/components/00-base/collapsible/collapsible')
}
}
catch(e) {
// eslint-disable-next-line
console.error(e)
}
},
beforeDestroy() {
delete require.cache[require.resolve('civictheme/components/00-base/collapsible/collapsible')]
}
}
</script>

0 comments on commit 89949d3

Please sign in to comment.