|
| 1 | +// Styles |
| 2 | +import './VIconBtn.scss' |
| 3 | + |
| 4 | +// Components |
| 5 | +import { VIcon } from '@/components/VIcon' |
| 6 | + |
| 7 | +// Composables |
| 8 | +import { makeBorderProps, useBorder } from '@/composables/border' |
| 9 | +import { useBackgroundColor, useTextColor } from '@/composables/color' |
| 10 | +import { makeComponentProps } from '@/composables/component' |
| 11 | +import { makeElevationProps, useElevation } from '@/composables/elevation' |
| 12 | +import { makeRoundedProps, useRounded } from '@/composables/rounded' |
| 13 | +import { makeTagProps } from '@/composables/tag' |
| 14 | +import { makeThemeProps, provideTheme } from '@/composables/theme' |
| 15 | + |
| 16 | +// Utilities |
| 17 | +import { toRef, toRefs } from 'vue' |
| 18 | +import { convertToUnit, genericComponent, propsFactory, useRender } from '@/util' |
| 19 | + |
| 20 | +// Types |
| 21 | +import type { PropType } from 'vue' |
| 22 | +import type { IconValue } from '@/composables/icons' |
| 23 | + |
| 24 | +export const makeVIconBtnProps = propsFactory({ |
| 25 | + bgColor: String, |
| 26 | + color: String, |
| 27 | + loading: Boolean, |
| 28 | + disabled: Boolean, |
| 29 | + readonly: Boolean, |
| 30 | + icon: [String, Function, Object] as PropType<IconValue>, |
| 31 | + rotate: [Number, String], |
| 32 | + size: [Number, String], |
| 33 | + text: { |
| 34 | + type: [String, Number, Boolean], |
| 35 | + default: undefined, |
| 36 | + }, |
| 37 | + |
| 38 | + ...makeBorderProps(), |
| 39 | + ...makeComponentProps(), |
| 40 | + ...makeElevationProps(), |
| 41 | + ...makeRoundedProps(), |
| 42 | + ...makeTagProps(), |
| 43 | + ...makeThemeProps(), |
| 44 | +}, 'VIconBtn') |
| 45 | + |
| 46 | +export const VIconBtn = genericComponent()({ |
| 47 | + name: 'VIconBtn', |
| 48 | + |
| 49 | + props: makeVIconBtnProps(), |
| 50 | + |
| 51 | + setup (props, { slots }) { |
| 52 | + const { color, bgColor } = toRefs(props) |
| 53 | + |
| 54 | + const { themeClasses } = provideTheme(props) |
| 55 | + const { textColorClasses, textColorStyles } = useTextColor(color) |
| 56 | + const { backgroundColorClasses, backgroundColorStyles } = useBackgroundColor(bgColor) |
| 57 | + const { borderClasses } = useBorder(props) |
| 58 | + const { elevationClasses } = useElevation(props) |
| 59 | + const { roundedClasses } = useRounded(props) |
| 60 | + |
| 61 | + useRender(() => ( |
| 62 | + <props.tag |
| 63 | + class={[ |
| 64 | + 'v-icon-btn', |
| 65 | + themeClasses.value, |
| 66 | + backgroundColorClasses.value, |
| 67 | + borderClasses.value, |
| 68 | + elevationClasses.value, |
| 69 | + roundedClasses.value, |
| 70 | + textColorClasses.value, |
| 71 | + props.class, |
| 72 | + ]} |
| 73 | + style={[ |
| 74 | + backgroundColorStyles.value, |
| 75 | + textColorStyles.value, |
| 76 | + props.style, |
| 77 | + { |
| 78 | + '--v-icon-btn-rotate: ': props.rotate, |
| 79 | + '--v-icon-btn-size': convertToUnit(props.size), |
| 80 | + }, |
| 81 | + ]} |
| 82 | + > |
| 83 | + { slots.default?.() ?? ( |
| 84 | + !props.icon ? props.text : ( |
| 85 | + <VIcon |
| 86 | + key="icon" |
| 87 | + icon={ props.icon } |
| 88 | + /> |
| 89 | + ) |
| 90 | + )} |
| 91 | + </props.tag> |
| 92 | + )) |
| 93 | + |
| 94 | + return {} |
| 95 | + }, |
| 96 | +}) |
| 97 | + |
| 98 | +export type VIconBtn = InstanceType<typeof VIconBtn> |
0 commit comments