diff --git a/_src /atoms/table-cell/TableCell.js b/_src /atoms/table-cell/TableCell.js deleted file mode 100644 index cff9de648..000000000 --- a/_src /atoms/table-cell/TableCell.js +++ /dev/null @@ -1,12 +0,0 @@ -// @vue/component -export default { - props: { - /** - * Tag for cell - */ - tag: { - type: String, - default: 'td' - } - } -} diff --git a/_src /atoms/table-cell/TableCell.scss b/_src /atoms/table-cell/TableCell.scss deleted file mode 100644 index fab60c456..000000000 --- a/_src /atoms/table-cell/TableCell.scss +++ /dev/null @@ -1,109 +0,0 @@ -@import '../../../assets/styles/globals'; - -$table__padding : $spacer--medium !default; -$table__cell__padding: $spacer $table__padding !default; -$table__background : $white !default; -$table__th-background: $gray-lightest !default; -$table__border : 1px solid $gray-light !default; -$table__border-bottom: none !default; -$table__border-radius: $border-radius !default; - -.table { - th { - display: none; - - &:last-child { - @include mq($screen-m) { - border-right: 0; - } - } - - @include mq($screen-m) { - display: table-cell; - padding: $table__padding; - background: $table__th-background; - border-right: $table__border; - border-bottom: $table__border; - } - } - - tr { - &:last-child { - border-bottom: $table__border-bottom; - - td { - @include mq($screen-m) { - border-bottom: $table__border-bottom; - } - - &:first-child { - @include mq($screen-m) { - border-bottom-left-radius: $table__border-radius; - } - } - - &:last-child { - @include mq($screen-m) { - border-bottom-right-radius: $table__border-radius; - } - } - } - } - } - - td { - display: flex; - padding: $table__cell__padding; - background: $table__background; - - &::before { - display: block; - width: 25%; - max-width: 25%; - margin-right: 10px; - font-weight: bold; - content: attr(data-th); - - @include mq($screen-m) { - display: none; - } - } - - &:last-child { - @include mq($screen-m) { - border-right: 0; - } - } - - @include mq($screen-m) { - display: table-cell; - padding: $table__padding; - background: $table__background; - border-right: $table__border; - border-bottom: $table__border; - } - } - - tfoot { - tr { - td { - display: block; - padding: $table__cell__padding; - background: $table__background; - border-bottom: $table__border-bottom; - - @include mq($screen-m) { - display: table-cell; - padding: $table__padding; - background: $table__th-background; - border-top: $table__border; - border-right: $table__border; - } - } - - &:first-child { - border-top: $table__border; - } - } - } -} diff --git a/_src /atoms/table-row/TableRow.scss b/_src /atoms/table-row/TableRow.scss deleted file mode 100644 index 381981d58..000000000 --- a/_src /atoms/table-row/TableRow.scss +++ /dev/null @@ -1,75 +0,0 @@ -@import '../../../assets/styles/globals'; - -$table__row__padding : $spacer--medium 0 !default; -$table__background--odd : $white !default; -$table__background--even: $gray-lightest !default; -$table__border : 1px solid $gray-light !default; -$table__border-radius : $border-radius !default; - -.table { - &--odd-even { - tbody { - tr { - &:nth-child(odd) { - background: $table__background--odd; - } - - &:nth-child(even) { - background: $table__background--even; - } - - &:first-child { - border-top-left-radius: $table__border-radius; - border-top-right-radius: $table__border-radius; - - @include mq($screen-m) { - border-top-left-radius: 0; - border-top-right-radius: 0; - } - } - } - - td { - background-color: transparent; - } - } - } - - tr { - display: block; - padding: $table__row__padding; - border-bottom: $table__border; - - @include mq($screen-m) { - display: table-row; - padding: 0; - border-bottom: 0; - } - } - - thead { - tr { - padding: 0; - border-bottom: 0; - - @include mq($screen-m) { - border-top-left-radius: $table__border-radius; - border-top-right-radius: $table__border-radius; - } - } - - th { - &:first-child { - @include mq($screen-m) { - border-top-left-radius: $table__border-radius; - } - } - - &:last-child { - @include mq($screen-m) { - border-top-right-radius: $table__border-radius; - } - } - } - } -} diff --git a/_src /atoms/table/Table.scss b/_src /atoms/table/Table.scss deleted file mode 100644 index 864423127..000000000 --- a/_src /atoms/table/Table.scss +++ /dev/null @@ -1,22 +0,0 @@ -@import '../../../assets/styles/globals'; - -$table__color : $black !default; -$table__background : $white !default; -$table__font-size : $font-size-small !default; -$table__border-radius: $border-radius !default; -$table__border : 1px solid $gray-light !default; - -.table { - width: 100%; - color: $table__color; - font-size: $table__font-size; - background: $table__background; - border: $table__border; - border-radius: $table__border-radius; - border-collapse: separate; - border-spacing: 0; - - &__caption { - @include visually-hidden(); - } -} diff --git a/_src /atoms/table/Table.stories.js b/_src /atoms/table/Table.stories.js deleted file mode 100644 index b40d14130..000000000 --- a/_src /atoms/table/Table.stories.js +++ /dev/null @@ -1,81 +0,0 @@ -import { storiesOf } from '@storybook/vue' -import { select } from '@storybook/addon-knobs' - -import bodyRows from './mocks/bodyRows.json' -import headCells from './mocks/headCells.json' -import footCells from './mocks/footCells.json' - -import generateVueInfoTable from '@utils/helpers/generate-vue-info-table.js' -import getClassKnobsConfig from '@utils/helpers/get-class-knobs-config.js' -import selectorsConfig from './Table.selectors.json' - -import ATable from './Table.vue' -import ATableRow from '../table-row/TableRow.vue' -import ATableCell from '../table-cell/TableCell.vue' - -const info = ` -

Check Knobs tab to edit component properties dynamically.


- ${generateVueInfoTable(selectorsConfig, 'BEM modifiers')} -` - -const classKnobsConfig = getClassKnobsConfig(selectorsConfig) - -storiesOf('Atoms/Table', module) - .addParameters({ info }) - .add('Default', () => ({ - components: { ATable, ATableRow, ATableCell }, - props: { - classKnobs: { - default: select('BEM Modifier', classKnobsConfig) - } - }, - data: () => ({ - bodyRows, - headCells, - footCells - }), - template: ` - - - - - {{ headCell.text }} - - - - - - - {{ bodyCell.text }} - - - - - - - {{ footCell.text }} - - - - - ` - })) diff --git a/src/atoms/table-cell/TableCell.css b/src/atoms/table-cell/TableCell.css new file mode 100644 index 000000000..8216efec9 --- /dev/null +++ b/src/atoms/table-cell/TableCell.css @@ -0,0 +1,112 @@ +.table th { + @apply hidden; +} + +@screen md { + .table th { + @apply table-cell; + @apply p-4; + @apply bg-gray-200; + @apply border-r border-b border-solid border-light; + @apply text-left; + } + + .table th:last-child { + @apply border-r-0; + } +} + +.table td { + @apply flex; + @apply py-2 px-4; + @apply bg-white; +} + +@screen md { + .table td { + @apply table-cell; + @apply p-4; + @apply border-r border-b border-solid border-light; + } + + .table td:last-child { + @apply border-r-0; + } +} + +.table td::before { + content: attr(data-th); + + @apply block; + @apply max-w-1/4 mr-2; + @apply w-1/4; + @apply font-bold; +} + +@screen md { + .table td::before { + @apply hidden; + } +} + +.table tr:last-child td { + @apply border-b-0; +} + +.table tfoot td { + @apply block; + @apply py-2 px-4; + @apply bg-white; +} + +@screen md { + .table tfoot td { + @apply table-cell; + @apply p-4; + @apply border-t border-r border-b-0 border-solid border-light; + } +} + +.table--odd-even tbody td { + @apply bg-transparent; +} + +.table--scope-row th { + @apply w-1/2; + @apply p-4; + @apply border-r-0; + @apply bg-white; + @apply font-normal; +} + +.table--scope-row tr:nth-child(odd) th, +.table--scope-row tr:nth-child(odd) td { + @apply bg-gray-200; +} + +.table--scope-row th + td { + @apply flex-col flex-no-wrap; + @apply p-4; +} + +@screen sm { + .table--scope-row th + td { + @apply flex-row; + } +} + +.table--scope-row th + td::before { + @apply max-w-full w-full; + @apply mb-2; +} + +@screen sm { + .table--scope-row th + td::before { + @apply max-w-1/2 w-1/2; + @apply mb-0; + } +} + +.table--scope-row tr:last-child td { + @apply border-b; +} diff --git a/_src /atoms/table-cell/TableCell.html b/src/atoms/table-cell/TableCell.html similarity index 71% rename from _src /atoms/table-cell/TableCell.html rename to src/atoms/table-cell/TableCell.html index 47a823c39..be536548e 100644 --- a/_src /atoms/table-cell/TableCell.html +++ b/src/atoms/table-cell/TableCell.html @@ -1,6 +1,7 @@ diff --git a/src/atoms/table-cell/TableCell.js b/src/atoms/table-cell/TableCell.js new file mode 100644 index 000000000..8aa6d05f4 --- /dev/null +++ b/src/atoms/table-cell/TableCell.js @@ -0,0 +1,26 @@ +// @vue/component +export default { + props: { + /** + * Tag for cell + */ + tag: { + type: String, + default: 'td' + }, + /** + * Cell role + */ + role: { + type: String, + default: 'gridcell' + }, + /** + * Cell scope + */ + scope: { + type: String, + default: null + } + } +} diff --git a/src/atoms/table-cell/TableCell.spec.js b/src/atoms/table-cell/TableCell.spec.js new file mode 100644 index 000000000..683701249 --- /dev/null +++ b/src/atoms/table-cell/TableCell.spec.js @@ -0,0 +1,34 @@ +import { mount } from '@vue/test-utils' +import TableCell from './TableCell.vue' + +describe('atoms/TableCell.vue', () => { + it('has default structure', () => { + const wrapper = mount(TableCell) + + expect(wrapper.element.tagName).toBe('TD') + expect(wrapper.element.tagName).toBe('TD') + expect(wrapper.attributes().role).toBeDefined() + expect(wrapper.attributes().role).toEqual('gridcell') + }) + + it('renders scope prop when passed', () => { + const wrapper = mount(TableCell, { + propsData: { + scope: 'row' + } + }) + + expect(wrapper.attributes().scope).toBeDefined() + expect(wrapper.attributes().scope).toEqual('row') + }) +}) + +it('renders slot text when passed', () => { + const wrapper = mount(TableCell, { + slots: { + default: 'Test table cell' + } + }) + + expect(wrapper.text()).toEqual('Test table cell') +}) diff --git a/_src /atoms/table-cell/TableCell.vue b/src/atoms/table-cell/TableCell.vue similarity index 78% rename from _src /atoms/table-cell/TableCell.vue rename to src/atoms/table-cell/TableCell.vue index f1f8fd4bd..c62912bcd 100644 --- a/_src /atoms/table-cell/TableCell.vue +++ b/src/atoms/table-cell/TableCell.vue @@ -5,9 +5,8 @@ import ATableCell from './TableCell.js' export default { name: 'AlpacaTableCell', - mixins: [ATableCell] } -