Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add disabled state to icon #294

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"devDependencies": {
"@esbuild-kit/cjs-loader": "^2.4.2",
"@pnpm/types": "^9.0.0",
"@rollup/plugin-json": "^6.1.0",
"@types/rollup-plugin-css-only": "^3.1.0",
"unbuild": "^1.2.0",
"vue": "^3.2.47"
Expand Down
3 changes: 3 additions & 0 deletions build/src/tasks/full-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import esbuild from 'rollup-plugin-esbuild'
import { parallel } from 'gulp'
import glob from 'fast-glob'
import { camelCase, upperFirst } from 'lodash-unified'
import json from '@rollup/plugin-json'
import { version } from '../../../packages/puik/version'
import { PuikAlias } from '../plugins/puik-alias'
import {
Expand Down Expand Up @@ -48,6 +49,7 @@ async function buildFullEntry(minify: boolean) {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
json(),
],
external: await generateExternal({ full: true }),
})
Expand Down Expand Up @@ -97,6 +99,7 @@ async function buildFullLocale(minify: boolean) {
sourceMap: minify,
target,
}),
json(),
],
})
await writeBundles(bundle, [
Expand Down
2 changes: 2 additions & 0 deletions build/src/tasks/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import esbuild from 'rollup-plugin-esbuild'
import glob from 'fast-glob'
import json from '@rollup/plugin-json'
import {
puikRoot,
pkgRoot,
Expand Down Expand Up @@ -44,6 +45,7 @@ export const buildModules = async () => {
'.vue': 'ts',
},
}),
json(),
],
external: await generateExternal({ full: false }),
treeshake: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/components/icon/src/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const iconProps = buildProps({
default: '#00000',
required: false,
},
isDisabled: {
type: Boolean,
default: false,
required: false,
},
} as const)

export type IconProps = ExtractPropTypes<typeof iconProps>
Expand Down
8 changes: 7 additions & 1 deletion packages/components/icon/src/icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@

<script setup lang="ts">
import { computed } from 'vue'
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from '@puik/tailwind-preset/theme'
import { iconProps } from './icon'

defineOptions({
name: 'PuikIcon',
})

const fullConf = resolveConfig(tailwindConfig)
const props = defineProps(iconProps)

const fontSize = computed(() => {
Expand All @@ -28,7 +32,9 @@ const fontSize = computed(() => {
const style = computed(() => {
return {
fontSize: fontSize.value,
color: props.color,
color: props.isDisabled
? fullConf.extend?.colors?.primary['500']
: props.color,
}
})
</script>
7 changes: 7 additions & 0 deletions packages/components/icon/stories/icon.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export default {
dataTest: {
description: 'Set the data-test attribute',
},
isDisabled: {
description: 'If the icon is disable',
control: {
type: 'boolean',
},
},
},
} as Meta

Expand All @@ -56,6 +62,7 @@ export const Default = {
fontSize: 24,
nodeType: 'span',
dataTest: '',
isDisabled: false,
},

parameters: {
Expand Down
13 changes: 13 additions & 0 deletions packages/components/icon/test/icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
expect(findIcon().text()).toBe('check')
})

it('should set the icon disabled', async () => {
factory({
icon: 'check',
color: 'red',
isDisabled: true,
})

expect(findIcon().element.style.color).toBe('rgb(187, 187, 187)')
})

it('should set the color', async () => {
factory({
icon: 'check',
Expand Down Expand Up @@ -74,3 +84,6 @@
expect(findIcon().attributes('data-test')).toBe('test')
})
})
function resolveConfig(tailwindConfig: any) {

Check warning on line 87 in packages/components/icon/test/icon.spec.ts

View workflow job for this annotation

GitHub Actions / puik-ci (ubuntu-latest, 18)

'resolveConfig' is defined but never used

Check warning on line 87 in packages/components/icon/test/icon.spec.ts

View workflow job for this annotation

GitHub Actions / puik-ci (ubuntu-latest, 18)

'tailwindConfig' is defined but never used
throw new Error('Function not implemented.')
}
6 changes: 6 additions & 0 deletions packages/puik/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"moduleResolution": "NodeNext",
"module": "NodeNext"
}
}
7 changes: 4 additions & 3 deletions packages/tailwind-preset/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Puiktheme = require('./theme')
// const Puiktheme = require('./theme')
import PuikTheme from './theme'

module.exports = {
theme: Puiktheme,
export default {
theme: PuikTheme,
}
3 changes: 2 additions & 1 deletion packages/tailwind-preset/theme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
/** @type {import('tailwindcss').Config} */
export default {
extend: {
colors: {
primary: {
Expand Down
4 changes: 3 additions & 1 deletion packages/theme/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import tailwindConfig from '@puik/tailwind-preset'

/* eslint-disable @typescript-eslint/no-var-requires */
module.exports = {
presets: [require('@puik/tailwind-preset')],
presets: [tailwindConfig],
content: ['./src/**/*.scss'],
plugins: [require('tailwind-scrollbar')({ nocompatible: true })],
darkMode: 'class', // To remove if we wanna use the css' prefers-color-scheme feature (dark mode based on OS/browser preference)
Expand Down
5 changes: 0 additions & 5 deletions packages/theme/tsconfig.json

This file was deleted.

28 changes: 23 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading