From e061d2643c389b242de9bf88b9a5605c972618e6 Mon Sep 17 00:00:00 2001 From: joffrey Date: Fri, 28 May 2021 16:51:44 +0200 Subject: [PATCH] create LcTooltip + LcButton with LcIcon --- README.md | 1 + package.json | 4 +- src/components/LcButton.vue | 69 +++++++++- src/components/LcCheckbox.vue | 6 +- src/components/LcTooltip.d.ts | 3 + src/components/LcTooltip.vue | 213 +++++++++++++++++++++++++++++++ src/main.ts | 2 + src/stories/LcButton.stories.ts | 30 ++++- src/stories/LcTooltip.stories.ts | 47 +++++++ src/validators/LcButton.ts | 11 +- src/validators/LcTooltip.ts | 5 + tailwind.config.js | 6 +- 12 files changed, 379 insertions(+), 18 deletions(-) create mode 100644 src/components/LcTooltip.d.ts create mode 100644 src/components/LcTooltip.vue create mode 100644 src/stories/LcTooltip.stories.ts create mode 100644 src/validators/LcTooltip.ts diff --git a/README.md b/README.md index 9616954..87c83b9 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This repo provides a basic setup for developing component libraries in Vite with - [x] LcModal - [x] LcPagination - [x] LcTable +- [x] LcTooltip ## Commands ```bash diff --git a/package.json b/package.json index 89cecb4..851b23f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lc-component-library", - "version": "1.2.8", + "version": "1.3.0", "license": "MIT", "files": [ "dist" @@ -9,7 +9,7 @@ "module": "./dist/lc-component-library.es.js", "types": "./dist/main.d.ts", "scripts": { - "build": "node build/exports.js && vite build && tsc --emitDeclarationOnly", + "build": "vite build", "storybook": "start-storybook -p 6006", "dev": "vite", "build-storybook": "build-storybook" diff --git a/src/components/LcButton.vue b/src/components/LcButton.vue index 69af295..3c2faa5 100644 --- a/src/components/LcButton.vue +++ b/src/components/LcButton.vue @@ -13,6 +13,7 @@ > + @@ -107,18 +108,40 @@ export default defineComponent({ grey: 'lc-outline--grey', disabled: 'lc-outline--disabled', }, + icon: { + primary: 'lc-icon--primary', + secondary: 'lc-icon--secondary', + red: 'lc-icon--red', + }, }, btnSizes: { - xs: 'lc-btn--xs', - sm: 'lc-btn--sm', - md: 'lc-btn--md', - lg: 'lc-btn--lg', - xl: 'lc-btn--xl', + btn: { + xs: 'lc-btn--xs', + sm: 'lc-btn--sm', + md: 'lc-btn--md', + lg: 'lc-btn--lg', + xl: 'lc-btn--xl', + }, + outline: { + xs: 'lc-btn--xs', + sm: 'lc-btn--sm', + md: 'lc-btn--md', + lg: 'lc-btn--lg', + xl: 'lc-btn--xl', + }, + icon: { + xs: 'lc-icon--xs', + sm: 'lc-icon--sm', + md: 'lc-icon--md', + lg: 'lc-icon--lg', + xl: 'lc-icon--xl', + }, }, btnVariants: { btn: 'lc-btn', link: 'lc-link', outline: 'lc-outline', + icon: 'lc-icon', }, } }, @@ -132,10 +155,12 @@ export default defineComponent({ // Variants const color = this.disabled ? 'disabled' : this.color as string const size = this.variant === 'link' ? '' : this.size as string + const blockClass: ComputedClass = { btn: this.block ? 'lc-btn--block' : '', link: this.block ? 'lc-link--block' : '', outline: this.block ? 'lc-outline--block' : '', + icon: this.block ? 'lc-icon--block' : '', } const blockFullClass: ComputedClass = { btn: this.blockFull ? 'lc-btn--block-full' : '', @@ -151,6 +176,7 @@ export default defineComponent({ btn: `lc-btn--${this.fontWeight}`, link: `lc-link--${this.fontWeight}`, outline: `lc-outline--${this.fontWeight}`, + icon: `lc-icon--${this.fontWeight}`, } return [ @@ -158,7 +184,7 @@ export default defineComponent({ blockFullClass[this.variant], hasIconClass[this.variant], this.btnColors[this.variant][color], - this.btnSizes[size], + this.btnSizes[this.variant][size], this.btnVariants[this.variant], weightClass[this.variant], ] @@ -174,6 +200,7 @@ export default defineComponent({ diff --git a/src/main.ts b/src/main.ts index a3d0b5a..6ce119b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import LcInput from './components/LcInput.vue' import LcModal from './components/LcModal.vue' import LcPagination from './components/LcPagination.vue' import LcTable from './components/LcTable.vue' +import LcTooltip from './components/LcTooltip.vue' export { LcButton, @@ -16,4 +17,5 @@ export { LcModal, LcPagination, LcTable, + LcTooltip, } diff --git a/src/stories/LcButton.stories.ts b/src/stories/LcButton.stories.ts index c39f780..cab77d7 100644 --- a/src/stories/LcButton.stories.ts +++ b/src/stories/LcButton.stories.ts @@ -1,4 +1,6 @@ import LcButton from '../components/LcButton' +import LcIcon from '../components/LcIcon' + import { vColor, vFontWeight, vSize, vVariant } from '../validators/LcButton' export default { @@ -20,14 +22,40 @@ const Template = (args: any) => ({ template: 'Hello world', }) +const TemplateIcon = (args: any) => ({ + components: { LcButton, LcIcon }, + setup() { + return { args } + }, + template: ` + + + `, +}) + export const Primary = Template.bind({}) as any Primary.args = { color: 'primary', variant: 'btn', } - export const Secondary = Template.bind({}) as any Secondary.args = { color: 'secondary', variant: 'btn', } + +export const IconPrimary = TemplateIcon.bind({}) as any +IconPrimary.args = { + color: 'primary', + variant: 'icon', +} +export const IconSecondary = TemplateIcon.bind({}) as any +IconSecondary.args = { + color: 'secondary', + variant: 'icon', +} +export const IconRed = TemplateIcon.bind({}) as any +IconRed.args = { + color: 'red', + variant: 'icon', +} diff --git a/src/stories/LcTooltip.stories.ts b/src/stories/LcTooltip.stories.ts new file mode 100644 index 0000000..a30b88a --- /dev/null +++ b/src/stories/LcTooltip.stories.ts @@ -0,0 +1,47 @@ +import LcTooltip from '../components/LcTooltip' +import LcButton from '../components/LcButton' + +import { vPosition, vVariant, vSize } from '../validators/LcTooltip' + +export default { + title: 'Example/LcTooltip', + component: LcTooltip, + argTypes: { + position: { control: { type: 'select', options: vPosition } }, + variant: { control: { type: 'select', options: vVariant } }, + size: { control: { type: 'select', options: vSize } }, + }, +} + +const Template = (args: any) => ({ + components: { LcTooltip, LcButton }, + setup() { + return { args } + }, + template: ` + + + + + + `, +}) + +export const Base = Template.bind({}) as any +Base.args = { + position: 'bottom', + variant: 'white', + blockFull: true, +} diff --git a/src/validators/LcButton.ts b/src/validators/LcButton.ts index a8de485..5f85bda 100644 --- a/src/validators/LcButton.ts +++ b/src/validators/LcButton.ts @@ -1,14 +1,15 @@ const vColor: string[] = [ - 'primary', + 'black', + 'grey', + 'light', 'primary-light', + 'primary', + 'red', 'secondary', - 'light', 'white', - 'grey', - 'black', ] const vFontWeight: string[] = ['font-bold', 'font-medium', 'font-normal'] const vSize: string[] = ['xs', 'sm', 'md', 'lg', 'xl'] -const vVariant: string[] = ['btn', 'link', 'outline'] +const vVariant: string[] = ['btn', 'link', 'outline', 'icon'] export { vColor, vFontWeight, vSize, vVariant } diff --git a/src/validators/LcTooltip.ts b/src/validators/LcTooltip.ts new file mode 100644 index 0000000..72fbf9c --- /dev/null +++ b/src/validators/LcTooltip.ts @@ -0,0 +1,5 @@ +const vPosition: string[] = ['top', 'left', 'right', 'bottom'] +const vVariant: string[] = ['grey', 'white'] +const vSize: string[] = ['small', 'medium'] + +export { vPosition, vVariant, vSize } diff --git a/tailwind.config.js b/tailwind.config.js index f55e2dc..237a27f 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -34,13 +34,17 @@ module.exports = { 500: '#195252', 600: '#0B4141', }, + red: { + 100: '#E38687', + 200: '#DC6869', + 300: '#EFCCC3', + }, transparent: 'transparent', 'primary-focus': '#dbbc8f40', 'secondary-focus': '#dbbc8f40', active: '#448084', black: '#202020', error: '#DC6869', - red: '#DC6869', white: '#ffffff', }, fontSize: {