From d16e44c0c1eaa7afd5100dcc00e7a804d362b38e Mon Sep 17 00:00:00 2001 From: Zuza Date: Fri, 3 Jul 2020 14:05:38 +0200 Subject: [PATCH 1/4] update label --- src/atoms/label/Label.css | 15 ++++++++ src/atoms/label/Label.html | 7 ++++ src/atoms/label/Label.js | 12 ++++++ src/atoms/label/Label.selectors.json | 10 +++++ src/atoms/label/Label.spec.js | 37 ++++++++++++++++++ src/atoms/label/Label.stories.js | 56 ++++++++++++++++++++++++++++ src/atoms/label/Label.vue | 13 +++++++ 7 files changed, 150 insertions(+) create mode 100644 src/atoms/label/Label.css create mode 100644 src/atoms/label/Label.html create mode 100644 src/atoms/label/Label.js create mode 100644 src/atoms/label/Label.selectors.json create mode 100644 src/atoms/label/Label.spec.js create mode 100644 src/atoms/label/Label.stories.js create mode 100644 src/atoms/label/Label.vue diff --git a/src/atoms/label/Label.css b/src/atoms/label/Label.css new file mode 100644 index 000000000..a8607b1d5 --- /dev/null +++ b/src/atoms/label/Label.css @@ -0,0 +1,15 @@ + +.a-label { + @apply block; + @apply mb-1; + @apply text-gray-600 font-normal text-base font-sans leading-relaxed; + @apply transition-none; +} + +.a-label--inline { + @apply mr-2; +} + +.a-label--hidden { + @apply sr-only; +} diff --git a/src/atoms/label/Label.html b/src/atoms/label/Label.html new file mode 100644 index 000000000..8588c5d2f --- /dev/null +++ b/src/atoms/label/Label.html @@ -0,0 +1,7 @@ + + + + diff --git a/src/atoms/label/Label.js b/src/atoms/label/Label.js new file mode 100644 index 000000000..881fbeeea --- /dev/null +++ b/src/atoms/label/Label.js @@ -0,0 +1,12 @@ +// @vue/component +export default { + props: { + /** + * To use another tag instead of 'label' + */ + tag: { + type: String, + default: 'label' + } + } +} diff --git a/src/atoms/label/Label.selectors.json b/src/atoms/label/Label.selectors.json new file mode 100644 index 000000000..936b292cd --- /dev/null +++ b/src/atoms/label/Label.selectors.json @@ -0,0 +1,10 @@ +[ + { + "name": ".a-label--inline", + "description": "Selector for applying inline styles" + }, + { + "name": ".a-label--hidden", + "description": "Selector for applying hidden styles, mainly used for accessibility purposes" + } +] diff --git a/src/atoms/label/Label.spec.js b/src/atoms/label/Label.spec.js new file mode 100644 index 000000000..7a1b3e216 --- /dev/null +++ b/src/atoms/label/Label.spec.js @@ -0,0 +1,37 @@ +import { mount } from '@vue/test-utils' +import ALabel from './Label.vue' + +describe('Label', () => { + it('has default structure', () => { + const wrapper = mount(ALabel) + + expect(wrapper.is('label')).toBe(true) + expect(wrapper.classes()).toContain('a-label') + expect(wrapper.classes().length).toBe(1) + }) + + it('renders custom root element', () => { + const wrapper = mount(ALabel, { + propsData: { + tag: 'span' + } + }) + + expect(wrapper.is('span')).toBe(true) + expect(wrapper.classes()).toContain('a-label') + expect(wrapper.classes().length).toBe(1) + }) + + it('renders slot text when passed', () => { + const wrapper = mount(ALabel, { + slots: { + default: ` + Alpaca UI + ` + } + }) + + expect(wrapper.find('label span').exists()).toBe(true) + expect(wrapper.find('label span').text()).toEqual('Alpaca UI') + }) +}) diff --git a/src/atoms/label/Label.stories.js b/src/atoms/label/Label.stories.js new file mode 100644 index 000000000..6f641f2af --- /dev/null +++ b/src/atoms/label/Label.stories.js @@ -0,0 +1,56 @@ +import { storiesOf } from '@storybook/vue' +import { select, text } from '@storybook/addon-knobs' + +import generateVueInfoTable from '@utils/helpers/generate-vue-info-table.js' +import getClassKnobsConfig from '@utils/helpers/get-class-knobs-config.js' +import selectorsConfig from './Label.selectors.json' + +import ALabel from './Label.vue' + +const info = ` +

Check Knobs tab to edit component properties dynamically.


+ ${generateVueInfoTable(selectorsConfig, 'BEM modifiers')} +` + +const classKnobsConfig = getClassKnobsConfig(selectorsConfig) + +storiesOf('Atoms/Label', module) + .addParameters({ info }) + .add('Default', () => ({ + components: { ALabel }, + props: { + classKnobs: { + default: select('BEM Modifier', classKnobsConfig) + }, + textKnobs: { + default: text('Text', 'Label') + } + }, + template: ` + + {{ textKnobs }} + + ` + })) + .add('Custom tag', () => ({ + components: { ALabel }, + props: { + classKnobs: { + default: select('BEM Modifier', classKnobsConfig) + }, + textKnobs: { + default: text('Text', 'Custom tag label') + }, + tagKnob: { + default: text('Html tag', 'span') + } + }, + template: ` + + {{ textKnobs }} + + ` + })) diff --git a/src/atoms/label/Label.vue b/src/atoms/label/Label.vue new file mode 100644 index 000000000..8a2dde632 --- /dev/null +++ b/src/atoms/label/Label.vue @@ -0,0 +1,13 @@ +