|
| 1 | +import { defineComponent, h } from 'vue' |
| 2 | + |
| 3 | +import { Color } from '../props' |
| 4 | + |
| 5 | +const BREAKPOINTS = [ |
| 6 | + 'xxl' as const, |
| 7 | + 'xl' as const, |
| 8 | + 'lg' as const, |
| 9 | + 'md' as const, |
| 10 | + 'sm' as const, |
| 11 | + 'xs' as const, |
| 12 | +] |
| 13 | + |
| 14 | +export const CPlaceholder = defineComponent({ |
| 15 | + name: 'CPlaceholder', |
| 16 | + props: { |
| 17 | + /** |
| 18 | + * Set animation type to better convey the perception of something being actively loaded. |
| 19 | + * |
| 20 | + * @values 'glow', 'wave' |
| 21 | + */ |
| 22 | + animation: { |
| 23 | + type: String, |
| 24 | + default: undefined, |
| 25 | + require: false, |
| 26 | + validator: (value: string) => { |
| 27 | + return ['glow', 'wave'].includes(value) |
| 28 | + }, |
| 29 | + }, |
| 30 | + /** |
| 31 | + * Sets the color context of the component to one of CoreUI’s themed colors. |
| 32 | + * |
| 33 | + * @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light' |
| 34 | + */ |
| 35 | + color: Color, |
| 36 | + /** |
| 37 | + * Component used for the root node. Either a string to use a HTML element or a component. |
| 38 | + */ |
| 39 | + component: { |
| 40 | + type: String, |
| 41 | + default: 'span', |
| 42 | + required: false, |
| 43 | + }, |
| 44 | + /** |
| 45 | + * Size the component extra small, small, or large. |
| 46 | + * |
| 47 | + * @values 'xs', 'sm', 'lg' |
| 48 | + */ |
| 49 | + size: { |
| 50 | + type: String, |
| 51 | + default: undefined, |
| 52 | + required: false, |
| 53 | + validator: (value: string) => { |
| 54 | + return ['xs', 'sm', 'lg'].includes(value) |
| 55 | + }, |
| 56 | + }, |
| 57 | + /** |
| 58 | + * The number of columns on extra small devices (<576px). |
| 59 | + */ |
| 60 | + xs: { |
| 61 | + type: Number, |
| 62 | + default: undefined, |
| 63 | + require: false, |
| 64 | + }, |
| 65 | + /** |
| 66 | + * The number of columns on small devices (<768px). |
| 67 | + */ |
| 68 | + sm: { |
| 69 | + type: Number, |
| 70 | + default: undefined, |
| 71 | + require: false, |
| 72 | + }, |
| 73 | + /** |
| 74 | + * The number of columns on medium devices (<992px). |
| 75 | + */ |
| 76 | + md: { |
| 77 | + type: Number, |
| 78 | + default: undefined, |
| 79 | + require: false, |
| 80 | + }, |
| 81 | + /** |
| 82 | + * The number of columns on large devices (<1200px). |
| 83 | + */ |
| 84 | + lg: { |
| 85 | + type: Number, |
| 86 | + default: undefined, |
| 87 | + require: false, |
| 88 | + }, |
| 89 | + /** |
| 90 | + * The number of columns on X-Large devices (<1400px). |
| 91 | + */ |
| 92 | + xl: { |
| 93 | + type: Number, |
| 94 | + default: undefined, |
| 95 | + require: false, |
| 96 | + }, |
| 97 | + /** |
| 98 | + * The number of columns on XX-Large devices (≥1400px). |
| 99 | + */ |
| 100 | + xxl: { |
| 101 | + type: Number, |
| 102 | + default: undefined, |
| 103 | + require: false, |
| 104 | + }, |
| 105 | + }, |
| 106 | + setup(props, { slots }) { |
| 107 | + const repsonsiveClassNames: string[] = [] |
| 108 | + |
| 109 | + BREAKPOINTS.forEach((bp) => { |
| 110 | + const breakpoint = props[bp] |
| 111 | + |
| 112 | + const infix = bp === 'xs' ? '' : `-${bp}` |
| 113 | + |
| 114 | + if (typeof breakpoint === 'number') { |
| 115 | + repsonsiveClassNames.push(`col${infix}-${breakpoint}`) |
| 116 | + } |
| 117 | + |
| 118 | + if (typeof breakpoint === 'boolean') { |
| 119 | + repsonsiveClassNames.push(`col${infix}`) |
| 120 | + } |
| 121 | + }) |
| 122 | + |
| 123 | + return () => |
| 124 | + h( |
| 125 | + props.component, |
| 126 | + { |
| 127 | + class: [ |
| 128 | + props.animation ? `placeholder-${props.animation}` : 'placeholder', |
| 129 | + { |
| 130 | + [`bg-${props.color}`]: props.color, |
| 131 | + [`placeholder-${props.size}`]: props.size, |
| 132 | + }, |
| 133 | + repsonsiveClassNames, |
| 134 | + ], |
| 135 | + }, |
| 136 | + slots.default && slots.default(), |
| 137 | + ) |
| 138 | + }, |
| 139 | +}) |
0 commit comments