@bwui/vue 0.1.8 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/stat.ts ADDED
@@ -0,0 +1,138 @@
1
+ import { defineComponent, h, type PropType } from 'vue'
2
+ import { cn } from './cn'
3
+
4
+ /** Size axis for Stat, StatComparison and StatCard (STA-003, CB-17 subset sm|md|lg). */
5
+ export type StatSize = 'sm' | 'md' | 'lg'
6
+
7
+ /** Chrome axis for Stat (STA-004). Default `card`. */
8
+ export type StatChrome = 'card' | 'plain'
9
+
10
+ /**
11
+ * Stat (docs/components/stat.md, D06 / R33).
12
+ * KPI tile rendering a label (overline) and a value (tabular numeral).
13
+ */
14
+ export const Stat = defineComponent({
15
+ name: 'BwStat',
16
+ props: {
17
+ label: { type: String, required: true },
18
+ value: { type: String, required: true },
19
+ size: { type: String as PropType<StatSize>, default: 'md' },
20
+ chrome: { type: String as PropType<StatChrome>, default: 'card' },
21
+ href: { type: String, default: undefined },
22
+ loading: { type: Boolean, default: false },
23
+ class: { type: String, default: '' },
24
+ },
25
+ setup(props, { slots }) {
26
+ return () => {
27
+ const cls = cn(
28
+ 'bw-stat',
29
+ `bw-stat--size-${props.size}`,
30
+ props.chrome === 'plain' && 'bw-stat--chrome-plain',
31
+ String(props.class || ''),
32
+ )
33
+
34
+ const inner = props.loading
35
+ ? [
36
+ h('div', { class: 'bw-skeleton bw-skeleton--text', 'aria-hidden': 'true' }),
37
+ h('div', { class: 'bw-skeleton bw-skeleton--title', 'aria-hidden': 'true' }),
38
+ ]
39
+ : [
40
+ h('span', { class: 'bw-stat__label' }, props.label),
41
+ h('span', { class: 'bw-stat__value' }, props.value),
42
+ slots.default?.(),
43
+ ]
44
+
45
+ if (props.href) {
46
+ return h('a', { href: props.href, class: cls }, inner)
47
+ }
48
+ return h('div', { class: cls }, inner)
49
+ }
50
+ },
51
+ })
52
+
53
+ /**
54
+ * StatComparison (STA-006). This-vs-last-period KPI tile.
55
+ */
56
+ export const StatComparison = defineComponent({
57
+ name: 'BwStatComparison',
58
+ props: {
59
+ current: { type: String, required: true },
60
+ previous: { type: String, required: true },
61
+ label: { type: String, default: undefined },
62
+ periodLabel: { type: String, default: undefined },
63
+ size: { type: String as PropType<StatSize>, default: 'md' },
64
+ class: { type: String, default: '' },
65
+ },
66
+ setup(props, { slots }) {
67
+ return () => {
68
+ const cls = cn(
69
+ 'bw-stat-comparison',
70
+ `bw-stat-comparison--size-${props.size}`,
71
+ String(props.class || ''),
72
+ )
73
+
74
+ const previousContent = props.periodLabel
75
+ ? [
76
+ props.previous,
77
+ h('span', { class: 'bw-stat-comparison__period' }, ` ${props.periodLabel}`),
78
+ ]
79
+ : [props.previous]
80
+
81
+ return h('div', { class: cls }, [
82
+ props.label && h('span', { class: 'bw-stat-comparison__label' }, props.label),
83
+ h('span', { class: 'bw-stat-comparison__current' }, props.current),
84
+ h('span', { class: 'bw-stat-comparison__previous' }, previousContent),
85
+ slots.default?.(),
86
+ ])
87
+ }
88
+ },
89
+ })
90
+
91
+ /**
92
+ * StatGrid: responsive auto-fit composition grid (STA-007).
93
+ */
94
+ export const StatGrid = defineComponent({
95
+ name: 'BwStatGrid',
96
+ props: {
97
+ class: { type: String, default: '' },
98
+ },
99
+ setup(props, { slots }) {
100
+ return () =>
101
+ h('div', { class: cn('bw-stat-grid', String(props.class || '')) }, slots.default?.())
102
+ },
103
+ })
104
+
105
+ /**
106
+ * StatCard: marketing stat card (D06, .bw-stat-card).
107
+ */
108
+ export const StatCard = defineComponent({
109
+ name: 'BwStatCard',
110
+ props: {
111
+ value: { type: String, required: true },
112
+ label: { type: String, required: true },
113
+ note: { type: String, default: undefined },
114
+ class: { type: String, default: '' },
115
+ },
116
+ setup(props) {
117
+ return () =>
118
+ h('div', { class: cn('bw-stat-card', String(props.class || '')) }, [
119
+ h('p', { class: 'bw-stat-card__value' }, props.value),
120
+ h('p', { class: 'bw-stat-card__label' }, props.label),
121
+ props.note && h('p', { class: 'bw-stat-card__note' }, props.note),
122
+ ])
123
+ },
124
+ })
125
+
126
+ /**
127
+ * StatCards: marketing stat-card grid container.
128
+ */
129
+ export const StatCards = defineComponent({
130
+ name: 'BwStatCards',
131
+ props: {
132
+ class: { type: String, default: '' },
133
+ },
134
+ setup(props, { slots }) {
135
+ return () =>
136
+ h('div', { class: cn('bw-stat-cards', String(props.class || '')) }, slots.default?.())
137
+ },
138
+ })