diff --git a/src/components/GBtn/__story__/__snapshots__/1-Button.stories.js.snap b/src/components/GBtn/__story__/__snapshots__/1-Button.stories.js.snap index aa6bda0d..46b4a436 100644 --- a/src/components/GBtn/__story__/__snapshots__/1-Button.stories.js.snap +++ b/src/components/GBtn/__story__/__snapshots__/1-Button.stories.js.snap @@ -7,3 +7,77 @@ exports[`test should test1 1`] = ` XLARGE BUTTON `; + +exports[`test should test1 2`] = ` + + + DEPRESSED BUTTON + + +`; + +exports[`test should test1 3`] = ` + + + + android + + + +`; + +exports[`test should test1 4`] = ` + + + GRADIENT BUTTON + + +`; + +exports[`test should test1 5`] = ` + + + + star + + + +`; + +exports[`test should test1 6`] = ` + + + OUTLINED BUTTON + + +`; + +exports[`test should test1 7`] = ` + + + ROUNDED BUTTON + + +`; + +exports[`test should test1 8`] = ` + + + TEXT BUTTON + + +`; diff --git a/src/components/GList/GList.vue b/src/components/GList/GList.vue index e342885a..0e2195b1 100644 --- a/src/components/GList/GList.vue +++ b/src/components/GList/GList.vue @@ -1,111 +1,111 @@ - - - - {{subheader}} - - - - - - - {{item.prepend}} - - - - - - - - {{item[itemTitle]}} - - {{item.subtitle|| ' '}} - - {{item.subtitle2||' '}} - - - {{item.append}} - - - + + + + + {{subheader}} - - - - - - - - {{item.subheader}} + + + + + + {{item.prepend}} + + + + + + + + {{item[itemText]||item}} + + {{item.subtext|| ' '}} + + {{item.subtext2||' '}} + + + {{item.append}} + + + + + + + + + + {{item.subheader}} + + - + - - - - - {{item.prepend}} - - - - + + + + + {{item.prepend}} + + + + + + {{item.prepend}} + + + + {{item[itemText]}} + + {{item.subtext || ' '}} + + {{item.subtext2||' '}} - {{item.prepend}} - + + {{item.append}} + - - {{item[itemTitle]}} - - {{item.subtitle || ' '}} - - {{item.subtitle2||' '}} - - - {{item.append}} - + + + + + - - - - - + diff --git a/src/components/GList/__story__/GList.stories.js b/src/components/GList/__story__/GList.stories.js index 08cb556e..e85fb784 100644 --- a/src/components/GList/__story__/GList.stories.js +++ b/src/components/GList/__story__/GList.stories.js @@ -1,19 +1,24 @@ import { boolean, number, text, withKnobs } from '@storybook/addon-knobs'; -import { action } from '@storybook/addon-actions'; import GList from '../GList'; import GListItem from '../GListItem'; import GDivider from '../../GLayout/GDivider.vue'; import { - GListItemIcon, - GListItemAvatar, + GListHeader, GListItemAction, + GListItemAvatar, + GListItemContent, + GListItemIcon, GListItemImage, GListItemImageBig, - GListItemContent, - GListItemText, GListItemSubText, - GListHeader + GListItemText } from '../GListFunctionalComponent' +import Vue from 'vue/dist/vue.common.js' +import GContainer from '../../GLayout/GContainer'; +import GRow from '../../GLayout/GRow'; +import GCol from '../../GLayout/GCol'; +import GIcon from '../../GIcon/GIcon'; +import GBtn from '../../GBtn/GBtn'; export default { title: 'GList', @@ -24,10 +29,12 @@ export const gListPlayGround = () => ({ data() { return { items: [ - { title: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -42,14 +49,15 @@ export const gListPlayGround = () => ({ subheader: { default: text('subheader', 'subheader') }, divider: { type: [String, Boolean], default: boolean('divider', false) }, prependType: { default: text('prependType', 'avatar') }, - subtitleWrap: { default: boolean('subtitleWrap', false) }, + subtextWrap: { default: boolean('subtextWrap', false) }, selectable: { default: boolean('selectable', false) }, multiple: { default: boolean('multiple', false) }, mandatory: { default: boolean('mandatory', false) }, allowDuplicates: { default: boolean('allowDuplicates', false) }, itemValue: { default: text('itemValue', '') }, - itemTitle: { default: text('itemTitle', 'title') }, + itemText: { default: text('itemText', 'text') }, activeClass: { default: text('activeClass', '') }, + returnObject: { default: boolean('returnObject', false) }, }, template: ` @@ -64,7 +72,12 @@ export const gListPlayGround = () => ({ :subheader="subheader" :divider="divider" :prependType="prependType" - :subtitleWrap="subtitleWrap" + :subtextWrap="subtextWrap" + :itemText="itemText" + :selectable="selectable" + :multiple="multiple" + :mandatory="mandatory" + :returnObject="returnObject" /> `, }) @@ -73,12 +86,12 @@ export const gListSingleSelectPlayGround = () => ({ data() { return { items: [ - { title: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], - testValue: null + testValue: '' } }, props: { @@ -92,11 +105,12 @@ export const gListSingleSelectPlayGround = () => ({ subheader: { default: text('subheader', 'subheader') }, divider: { type: [String, Boolean], default: boolean('divider', false) }, prependType: { default: text('prependType', 'avatar') }, - subtitleWrap: { default: boolean('subtitleWrap', false) }, + subtextWrap: { default: boolean('subtextWrap', false) }, mandatory: { default: boolean('mandatory', false) }, - itemValue: { default: text('itemValue', '') }, - itemTitle: { default: text('itemTitle', 'title') }, + itemValue: { default: text('itemValue', 'prepend') }, + itemText: { default: text('itemText', 'text') }, activeClass: { default: text('activeClass', '') }, + returnObject: { default: boolean('returnObject', true) }, }, template: ` @@ -113,12 +127,14 @@ export const gListSingleSelectPlayGround = () => ({ :subheader="subheader" :divider="divider" :prependType="prependType" - :subtitleWrap="subtitleWrap" + :subtextWrap="subtextWrap" selectable :mandatory="mandatory" :itemValue="itemValue" - :itemTitle="itemTitle" - :activeClass="activeClass"> + :itemText="itemText" + :activeClass="activeClass" + :returnObject="returnObject" + > `, @@ -128,12 +144,12 @@ export const gListMultiSelectPlayGround = () => ({ data() { return { items: [ - { title: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], - testValue: null + testValue: ['Jason Oner'] } }, props: { @@ -147,13 +163,14 @@ export const gListMultiSelectPlayGround = () => ({ subheader: { default: text('subheader', 'subheader') }, divider: { type: [String, Boolean], default: boolean('divider', false) }, prependType: { default: text('prependType', 'avatar') }, - subtitleWrap: { default: boolean('subtitleWrap', false) }, + subtextWrap: { default: boolean('subtextWrap', false) }, multiple: { default: boolean('multiple', true) }, mandatory: { default: boolean('mandatory', false) }, allowDuplicates: { default: boolean('allowDuplicates', true) }, - itemValue: { default: text('itemValue', '') }, - itemTitle: { default: text('itemTitle', 'title') }, + itemValue: { default: text('itemValue', 'text') }, + itemText: { default: text('itemText', 'text') }, activeClass: { default: text('activeClass', '') }, + returnObject: { default: boolean('returnObject', false) }, }, template: ` @@ -170,13 +187,14 @@ export const gListMultiSelectPlayGround = () => ({ :subheader="subheader" :divider="divider" :prependType="prependType" - :subtitleWrap="subtitleWrap" + :subtextWrap="subtextWrap" selectable :multiple="multiple" :mandatory="mandatory" :allowDuplicates="allowDuplicates" :itemValue="itemValue" - :itemTitle="itemTitle" + :itemText="itemText" + :returnObject="returnObject" :activeClass="activeClass"> @@ -187,10 +205,10 @@ export const gListInset = () => ({ data() { return { items: [ - { title: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/1.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', prepend: 'https://cdn.vuetifyjs.com/images/lists/1.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -209,10 +227,10 @@ export const gListDense = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -224,7 +242,7 @@ export const gListDense = () => ({ Two-line Two-line with wrapper - + `, }) export const gListShapedInset = () => ({ @@ -232,10 +250,10 @@ export const gListShapedInset = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -255,10 +273,10 @@ export const gListNav = () => ({ data() { return { items: [ - {title: 'Jason Oner', subtitle: "Jason the ant", prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg'}, - {title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg'}, - {title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg'}, - {title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg'}, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -277,10 +295,10 @@ export const gListTwoLine = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects.', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects.', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], } @@ -296,16 +314,16 @@ export const gListTwoLineWithWrapper = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', subtitle: 'Ranee the cockroach', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant, ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', subtext: 'Ranee the cockroach', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, template: ` - + `, }) @@ -314,16 +332,16 @@ export const gListThreeLine = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', subtitle2: 'ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', subtext2: 'ants work together to gather food and care for the young, and their behavior is surprisingly coordinated and methodical for such seemingly simple insects. ', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, template: ` - + `, }) @@ -332,10 +350,10 @@ export const gListPrependWithSlot = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -353,10 +371,10 @@ export const gListAppendWithSlot = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -375,12 +393,12 @@ export const gListNormalPrependAvatar = () => ({ return { items: [ { subheader: 'User', type: 'subheader' }, - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, { type: 'divider' }, { subheader: 'Admin', type: 'subheader' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, { subheader: 'Admin', type: 'subheader' }, ] @@ -399,12 +417,12 @@ export const gListNormalPrependIcon = () => ({ return { items: [ { subheader: 'User', type: 'subheader' }, - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'mdi-pen' }, - { title: 'Ranee Carlson', prepend: 'mdi-ninja' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'mdi-pen' }, + { text: 'Ranee Carlson', prepend: 'mdi-ninja' }, { type: 'divider' }, { subheader: 'Admin', type: 'subheader' }, - { title: 'Cindy Baker', prepend: 'mdi-glasses' }, - { title: 'Ali Connors', prepend: 'mdi-mail' }, + { text: 'Cindy Baker', prepend: 'mdi-glasses' }, + { text: 'Ali Connors', prepend: 'mdi-mail' }, { subheader: 'Admin', type: 'subheader' }, ] @@ -422,10 +440,10 @@ export const gListNormalPrependImg = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ] } }, @@ -442,12 +460,12 @@ export const gListMultiSection = () => ({ return { items: [ { subheader: 'User', type: 'subheader' }, - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, { type: 'divider' }, { subheader: 'Admin', type: 'subheader' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, /*{subheader: 'Admin', type: 'subheader'},*/ ] } @@ -464,10 +482,10 @@ export const gListSingleSectionSelect = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], testValue: 1 } @@ -488,12 +506,12 @@ export const gListMultiSectionSelect = () => ({ return { items: [ { subheader: 'User', type: 'subheader' }, - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, { type: 'divider' }, { subheader: 'Admin', type: 'subheader' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, /*{subheader: 'Admin', type: 'subheader'},*/ ], testValue: 1, @@ -514,10 +532,10 @@ export const gListItemSlotRenderArray = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], testValue: 1 } @@ -530,7 +548,7 @@ export const gListItemSlotRenderArray = () => ({ - {{item.title}} + {{item.text}} @@ -544,10 +562,10 @@ export const gListMultiSelect = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], testValue: null } @@ -572,10 +590,10 @@ export const gListSelectMandatory = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], testValue: null } @@ -595,10 +613,10 @@ export const gListCustomActiveClass = () => ({ data() { return { items: [ - { title: 'Jason Oner', subtitle: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, - { title: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, - { title: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, + { text: 'Jason Oner', subtext: 'Jason the ant', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Ranee Carlson', prepend: 'https://cdn.vuetifyjs.com/images/lists/2.jpg' }, + { text: 'Cindy Baker', prepend: 'https://cdn.vuetifyjs.com/images/lists/3.jpg' }, + { text: 'Ali Connors', prepend: 'https://cdn.vuetifyjs.com/images/lists/4.jpg' }, ], testValue: null } @@ -620,19 +638,19 @@ export const gListAsMenuContent = () => ({ data() { return { list1: [ - { title: 'Profile', prepend: 'person' }, - { title: 'Chat', prepend: 'chat' }, - { title: 'Help', prepend: 'help' }, + { text: 'Profile', prepend: 'person' }, + { text: 'Chat', prepend: 'chat' }, + { text: 'Help', prepend: 'help' }, { type: 'divider' }, - { title: 'Lock', prepend: 'lock' }, - { title: 'Log out', prepend: 'keyboard_tab' }, + { text: 'Lock', prepend: 'lock' }, + { text: 'Log out', prepend: 'keyboard_tab' }, ], list2:[ - { title: ' A new order has been placed!', subtitle: '2 hours ago', prepend: 'add_shopping_cart', color: 'cyan' }, - { title: ' Completed the task', subtitle: '3 days ago', prepend: 'star', color: 'red' }, - { title: ' Settings updated', subtitle: '4 days ago', prepend: 'settings', color: 'teal' }, - { title: ' Settings updated', subtitle: '6 days ago', prepend: 'today', color: 'deep-orange' }, - { title: ' Generate monthly report', subtitle: '1 week ago', prepend: 'trending_up', color: 'amber' }, + { text: ' A new order has been placed!', subtext: '2 hours ago', prepend: 'add_shopping_cart', color: 'cyan' }, + { text: ' Completed the task', subtext: '3 days ago', prepend: 'star', color: 'red' }, + { text: ' Settings updated', subtext: '4 days ago', prepend: 'settings', color: 'teal' }, + { text: ' Settings updated', subtext: '6 days ago', prepend: 'today', color: 'deep-orange' }, + { text: ' Generate monthly report', subtext: '1 week ago', prepend: 'trending_up', color: 'amber' }, ], testValue: null } @@ -674,7 +692,8 @@ export const gListPrimitiveItems = () => ({ components: { GDivider, GListItem, GList, GListItemIcon, GListItemAvatar, GListItemAction, GListItemImage, GListItemImageBig, GListItemContent, GListItemText, GListItemSubText, GListHeader }, data() { return { - items: ['Jason Oner', 'Ranee Carlson', 'Cindy Baker', 'Ali Connors'] + items: ['Jason Oner', 'Jason Oner', 'Jason Oner', 'Ranee Carlson', 'Cindy Baker', 'Ali Connors'], + selectedValue: null } }, props: { @@ -688,17 +707,20 @@ export const gListPrimitiveItems = () => ({ subheader: { default: text('subheader', 'subheader') }, divider: { type: [String, Boolean], default: boolean('divider', false) }, prependType: { default: text('prependType', 'avatar') }, - subtitleWrap: { default: boolean('subtitleWrap', false) }, - selectable: { default: boolean('selectable', false) }, - multiple: { default: boolean('multiple', false) }, + subtextWrap: { default: boolean('subtextWrap', false) }, + selectable: { default: boolean('selectable', true) }, + multiple: { default: boolean('multiple', true) }, mandatory: { default: boolean('mandatory', false) }, allowDuplicates: { default: boolean('allowDuplicates', false) }, itemValue: { default: text('itemValue', '') }, - itemTitle: { default: text('itemTitle', 'title') }, + itemText: { default: text('itemText', '') }, activeClass: { default: text('activeClass', '') }, + }, template: ` + +{{selectedValue}} ({ :subheader="subheader" :divider="divider" :prependType="prependType" - :subtitleWrap="subtitleWrap" + :subtextWrap="subtextWrap" + :selectable="selectable" + :multiple="multiple" + :mandatory="mandatory" + allowDuplicates + v-model="selectedValue" /> + + `, }) -import Vue from 'vue/dist/vue.common.js' -import GContainer from '../../GLayout/GContainer'; -import GRow from '../../GLayout/GRow'; -import GCol from '../../GLayout/GCol'; -import GIcon from '../../GIcon/GIcon'; -import GBtn from '../../GBtn/GBtn'; +export const gListFreeRender = () => ({ + components: { GList, GIcon, GListItemIcon, GContainer, GDivider, GRow, GBtn, GListItem, GListItemContent }, + data() { + return { + testValue: null, + items:[ + {text: 'item1', value: 1}, + {text: 'item2', value: 2}, + {text: 'item3', value: 3}, + ] + } + }, + + template: + ` + + {{testValue}} + + + + Item 1 + + + Item 2 + + + Item 3 + + + + `, +}) describe('GList', function () { diff --git a/src/mixins/groupable.js b/src/mixins/groupable.js index 67515711..39fbb235 100644 --- a/src/mixins/groupable.js +++ b/src/mixins/groupable.js @@ -1,67 +1,58 @@ import _ from 'lodash' -import { computed, ref, watch } from '@vue/composition-api'; +import {ref, watch} from '@vue/composition-api' function groupable(props, vModel) { //mandatory: requires at least 1 to be active at all times, unless value is null/undefined (at init) //multiple: multiple items can be active at a time //allowDuplicate: choose one item multiple times - const { returnObject = true, items, mandatory, multiple, allowDuplicates, maxSelection } = props + if (typeof props.returnObject === 'undefined') props.returnObject = true + const toggleItem = (item) => { - if (multiple) { - if (returnObject) { - updateMultiple(item); - } else { - updateMultiple(items.indexOf(item)) - } + if (props.multiple) { + if (props.returnObject && props.itemText) updateMultiple(item) + else props.itemValue ? updateMultiple(item[props.itemValue]) : updateMultiple(props.items.indexOf(item)) } else { - if (returnObject) { - updateSingle(item); - } else { - updateSingle(items.indexOf(item)) - } + if (props.returnObject && props.itemText) updateSingle(item) + else props.itemValue ? updateSingle(item[props.itemValue]) : updateSingle(props.items.indexOf(item)) } - }; + } const updateSingle = (item) => { - const isSame = _.isEqual(vModel.value, item); - if (isSame && mandatory) { - return; - } - vModel.value = isSame ? null : item; - }; + const isSame = vModel.value === item + + if (isSame && props.mandatory) return + + vModel.value = isSame ? null : item + } const updateMultiple = (item) => { - const clonedValue = _.clone(vModel.value); - const itemIndex = clonedValue.findIndex((i) => i === item); - //item exists + mandatory - if (itemIndex > -1 && mandatory && clonedValue.length - 1 < 1) { - return; - } - if (itemIndex > -1 && !allowDuplicates) { - clonedValue.splice(itemIndex, 1); + // use isNil because !0 will return true + if (_.isNil(vModel.value)) vModel.value = [] + + const itemIndex = vModel.value.findIndex(e => e === item) + if (itemIndex > -1) { + if (props.mandatory && vModel.value.length < 2) return + + if (!props.allowDuplicates) vModel.value.splice(itemIndex, 1) } else { - if (maxSelection) { - if (clonedValue.length < maxSelection) { - clonedValue.push(item); - } else { - return; - } - } else { - clonedValue.push(item); - } + if (!props.maxSelection || vModel.value.length < props.maxSelection) vModel.value.push(item) } - vModel.value = clonedValue; - }; + } const isActiveItem = (item) => { - if (multiple) { - return returnObject - ? vModel.value.some(element => _.isEqual(element, item)) - : vModel.value.includes(items.indexOf(item)) - } - return returnObject - ? _.isEqual(vModel.value, item) - : items.indexOf(item) === vModel.value + // use isNil because !0 will return true + if (_.isNil(vModel.value)) return false + + if (!props.returnObject) item = props.items.indexOf(item) + + if (props.multiple) + return props.itemValue + ? vModel.value.includes(item[props.itemValue]) + : vModel.value.includes(item) + else + return props.itemValue + ? vModel.value === item[props.itemValue] + : vModel.value === item }; return { @@ -73,16 +64,30 @@ function groupable(props, vModel) { export function makeSelectable(props, context) { // 1 -> {a: 1, b: 2} const convertValueToInternalValue = function (value) { - if (!props.itemValue || !value) return value; - if (!Array.isArray(props.value)) return props.items.find(i => i[props.itemValue] === value); - return props.items.filter(i => value.includes(i[props.itemValue])); + if (!props.itemValue || !value) { + return value; + } + if (!Array.isArray(props.value)) { + return props.returnObject + ? props.items.find(i => i[props.itemValue] === value) + : props.items.find(i => i[props.itemValue] === value)[props.itemValue]; + } + if (props.returnObject) { + return props.items.filter(i => value.includes(i[props.itemValue])) + } else if (props.itemValue) { + return value + } } // {a: 1, b: 2} -> 1 const convertInternalValueToValue = function (internalValue) { - if (!props.itemValue || !internalValue) return internalValue; - if (!Array.isArray(internalValue)) return internalValue[props.itemValue]; - return internalValue.map(i => i[props.itemValue]); + if (!props.itemValue || !internalValue) { + return internalValue; + } + if (!Array.isArray(internalValue)) { + return props.returnObject ? internalValue : internalValue[props.itemValue]; + } + return internalValue.map(i => props.returnObject ? i : i); } let rawInternalValue; @@ -97,6 +102,11 @@ export function makeSelectable(props, context) { let ignoreWatchValue = false; let ignoreWatchInternalValue = false; + watch(() => props.multiple, () => { + if (props.multiple) rawInternalValue.value = []; + else rawInternalValue.value = null; + }, {flush: "pre"}) + //use when props.value is change from outside watch(() => props.value, () => { if (ignoreWatchValue) {