Skip to content

Commit

Permalink
feat: use custom color names in button
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ksem committed Aug 26, 2024
1 parent 7d7ce3b commit 5acf074
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/ui/src/components/va-button/VaButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ import { VaIcon } from '../va-icon'
import { VaProgressCircle } from '../va-progress-circle'
import { pick } from '../../utils/pick'
import type { ColorName } from '../../composables'
defineOptions({
name: 'VaButton',
})
Expand All @@ -89,7 +91,7 @@ const props = defineProps({
block: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
color: { type: String, default: 'primary' },
color: { type: String as PropType<ColorName>, default: 'primary' },
textColor: { type: String, default: '' },
textOpacity: { type: [Number, String], default: 1 },
backgroundOpacity: { type: [Number, String], default: 1 },
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/src/services/color/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ type Capitalize<S extends string> = S extends `${infer First}${infer Rest}`
: S
type OnColors = `on${Capitalize<keyof EssentialVariables | keyof CustomColorVariables>}`

// string & Record<never, never> is a hack to make TypeScript suggest all possible values of the type
export type ColorVariables = EssentialVariables & CustomColorVariables & {
[key in OnColors]?: CssColor
} & Record<string, CssColor>
} & Record<string & Record<never, never>, CssColor>

export type ColorName = keyof ColorVariables | keyof CustomColorVariables // Force keyof, otherwise empty interface will be omitted in build!!!

export type ColorConfig = {
variables: ColorVariables,
Expand Down

0 comments on commit 5acf074

Please sign in to comment.