@cfasim-ui/docs 0.4.15 → 0.5.0
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/charts/BarChart/BarChart.md +134 -0
- package/charts/BarChart/BarChart.vue +512 -9
- package/charts/DataTable/DataTable.md +168 -3
- package/charts/DataTable/DataTable.vue +133 -11
- package/charts/LineChart/LineChart.md +5 -1
- package/charts/LineChart/LineChart.vue +35 -0
- package/charts/_shared/chartProps.ts +7 -0
- package/charts/_shared/contrast.ts +100 -0
- package/charts/_shared/index.ts +7 -0
- package/charts/_shared/useChartFoundation.ts +6 -0
- package/charts/_shared/useChartMenu.ts +18 -1
- package/charts/env.d.ts +4 -0
- package/components/Icon/Icon.md +122 -1
- package/components/Icon/Icon.vue +43 -51
- package/components/Icon/defaultIcons.ts +92 -0
- package/components/Icon/github.svg +1 -0
- package/components/Icon/registry.ts +68 -0
- package/components/ParamEditor/ParamEditorImpl.vue +8 -5
- package/components/index.ts +3 -0
- package/components/svg.d.ts +5 -0
- package/index.json +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,8 @@ export interface ChartMenuOptions {
|
|
|
11
11
|
getCsv: () => string;
|
|
12
12
|
/** Whether a separate download link is rendered (and the CSV menu item should be hidden). */
|
|
13
13
|
downloadLink: () => boolean | string | undefined;
|
|
14
|
+
/** Whether a separate download button is rendered (and the CSV menu item should be hidden). */
|
|
15
|
+
downloadButton?: () => boolean | string | undefined;
|
|
14
16
|
/**
|
|
15
17
|
* When true, prepends an Expand/Collapse menu item that toggles the
|
|
16
18
|
* chart into a full-window view. The consumer is responsible for
|
|
@@ -56,7 +58,8 @@ export function useChartMenu(opts: ChartMenuOptions) {
|
|
|
56
58
|
},
|
|
57
59
|
},
|
|
58
60
|
);
|
|
59
|
-
|
|
61
|
+
const buttonOn = opts.downloadButton?.();
|
|
62
|
+
if (!opts.downloadLink() && !buttonOn) {
|
|
60
63
|
out.push({
|
|
61
64
|
label: "Download CSV",
|
|
62
65
|
action: () => downloadCsv(opts.getCsv(), fname),
|
|
@@ -66,21 +69,35 @@ export function useChartMenu(opts: ChartMenuOptions) {
|
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
const downloadLinkText = computed<string | null>(() => {
|
|
72
|
+
if (opts.downloadButton?.()) return null;
|
|
69
73
|
const v = opts.downloadLink();
|
|
70
74
|
if (!v) return null;
|
|
71
75
|
return typeof v === "string" ? v : "Download data (CSV)";
|
|
72
76
|
});
|
|
73
77
|
|
|
74
78
|
const csvHref = computed<string | null>(() => {
|
|
79
|
+
if (opts.downloadButton?.()) return null;
|
|
75
80
|
if (!opts.downloadLink()) return null;
|
|
76
81
|
return `data:text/csv;charset=utf-8,${encodeURIComponent(opts.getCsv())}`;
|
|
77
82
|
});
|
|
78
83
|
|
|
84
|
+
const downloadButtonText = computed<string | null>(() => {
|
|
85
|
+
const v = opts.downloadButton?.();
|
|
86
|
+
if (!v) return null;
|
|
87
|
+
return typeof v === "string" ? v : "Download data (CSV)";
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
function triggerCsvDownload() {
|
|
91
|
+
downloadCsv(opts.getCsv(), resolvedFilename());
|
|
92
|
+
}
|
|
93
|
+
|
|
79
94
|
return {
|
|
80
95
|
svgRef: svgRef as Ref<SVGSVGElement | null>,
|
|
81
96
|
items,
|
|
82
97
|
downloadLinkText,
|
|
83
98
|
csvHref,
|
|
99
|
+
downloadButtonText,
|
|
100
|
+
triggerCsvDownload,
|
|
84
101
|
resolvedFilename,
|
|
85
102
|
isFullscreen: fullscreen?.isFullscreen ?? ref(false),
|
|
86
103
|
};
|
package/charts/env.d.ts
ADDED
package/components/Icon/Icon.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Icon
|
|
2
2
|
|
|
3
|
-
Renders a [Material Symbols
|
|
3
|
+
Renders a [Material Symbols](https://fonts.google.com/icons) icon as an inline
|
|
4
|
+
SVG. Icons are resolved from a registry by name, so you reference them exactly as
|
|
5
|
+
before — `<Icon icon="help" />` — but no webfont is loaded: only the SVGs you
|
|
6
|
+
actually use end up in your bundle.
|
|
7
|
+
|
|
8
|
+
A [base set](#base-set) of common icons is pre-registered and works with zero
|
|
9
|
+
setup. These SVGs are bundled inside `cfasim-ui`, so they need no extra install
|
|
10
|
+
or config — just `<Icon icon="help" />`. To use any other icon,
|
|
11
|
+
[register it](#registering-icons).
|
|
4
12
|
|
|
5
13
|
## Examples
|
|
6
14
|
|
|
@@ -52,6 +60,119 @@ Renders a [Material Symbols Outlined](https://fonts.google.com/icons) icon.
|
|
|
52
60
|
</template>
|
|
53
61
|
</ComponentDemo>
|
|
54
62
|
|
|
63
|
+
## Base set
|
|
64
|
+
|
|
65
|
+
These icons are bundled with `cfasim-ui` and need no install or registration —
|
|
66
|
+
just pass the name to `icon`. Anything not listed here must be
|
|
67
|
+
[registered](#registering-icons).
|
|
68
|
+
|
|
69
|
+
<script setup>
|
|
70
|
+
const baseIcons = [
|
|
71
|
+
"help", "favorite", "dark_mode", "light_mode",
|
|
72
|
+
"chevron_left", "chevron_right", "keyboard_arrow_up", "keyboard_arrow_down",
|
|
73
|
+
"keyboard_double_arrow_left", "keyboard_double_arrow_right",
|
|
74
|
+
"arrow_upward", "arrow_downward", "arrow_back", "arrow_forward",
|
|
75
|
+
"menu", "more_vert", "more_horiz",
|
|
76
|
+
"add", "edit", "delete", "close", "check", "search", "tune", "download",
|
|
77
|
+
"github",
|
|
78
|
+
];
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<Grid class="base-icons" :cols="4" :colsSmall="2" gap="sm">
|
|
82
|
+
<div v-for="name in baseIcons" :key="name" class="base-icons__cell">
|
|
83
|
+
<Icon :icon="name" size="lg" :aria-label="name" />
|
|
84
|
+
<code>{{ name }}</code>
|
|
85
|
+
</div>
|
|
86
|
+
</Grid>
|
|
87
|
+
|
|
88
|
+
<style>
|
|
89
|
+
.base-icons__cell {
|
|
90
|
+
display: flex;
|
|
91
|
+
flex-direction: column;
|
|
92
|
+
align-items: center;
|
|
93
|
+
gap: 0.5rem;
|
|
94
|
+
padding: 0.75rem 0.5rem;
|
|
95
|
+
border: 1px solid var(--vp-c-divider);
|
|
96
|
+
border-radius: 8px;
|
|
97
|
+
text-align: center;
|
|
98
|
+
}
|
|
99
|
+
.base-icons__cell code {
|
|
100
|
+
font-size: 0.65rem;
|
|
101
|
+
word-break: break-word;
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
104
|
+
|
|
105
|
+
`favorite` also has a filled variant via `:fill="true"`.
|
|
106
|
+
|
|
107
|
+
## Registering icons
|
|
108
|
+
|
|
109
|
+
The base set above is bundled with `cfasim-ui` and needs none of the steps below
|
|
110
|
+
— this section is only for additional icons. `cfasim-ui` does not depend on
|
|
111
|
+
`@material-symbols/svg-400`, so you install the icons yourself; each one you
|
|
112
|
+
import is inlined into _your_ bundle (still no webfont).
|
|
113
|
+
|
|
114
|
+
### 1. Install the icons and the Vite SVG loader
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
pnpm add -D @material-symbols/svg-400 vite-svg-loader
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 2. Add `svgLoader` to your Vite config
|
|
121
|
+
|
|
122
|
+
Add it to your existing `plugins` array — leave the other plugins in place:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
// vite.config.ts
|
|
126
|
+
import svgLoader from "vite-svg-loader";
|
|
127
|
+
|
|
128
|
+
export default defineConfig({
|
|
129
|
+
plugins: [
|
|
130
|
+
// ...your existing plugins
|
|
131
|
+
svgLoader(),
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 3. Register the icons once at startup
|
|
137
|
+
|
|
138
|
+
Import each SVG from the `outlined` style with the `?component` query, then pass
|
|
139
|
+
them to `registerIcons`. The key you register is the name you pass to `icon`.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
// main.ts
|
|
143
|
+
import rocket from "@material-symbols/svg-400/outlined/rocket.svg?component";
|
|
144
|
+
import settings from "@material-symbols/svg-400/outlined/settings.svg?component";
|
|
145
|
+
import { registerIcons } from "@cfasim-ui/components";
|
|
146
|
+
|
|
147
|
+
registerIcons({ rocket, settings });
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 4. Use them by name
|
|
151
|
+
|
|
152
|
+
```vue
|
|
153
|
+
<Icon icon="rocket" />
|
|
154
|
+
<Icon icon="settings" size="lg" />
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
An unregistered name renders nothing and logs a one-time console warning with the
|
|
158
|
+
exact code to register it.
|
|
159
|
+
|
|
160
|
+
### Filled variants
|
|
161
|
+
|
|
162
|
+
To support `:fill="true"` on a registered icon, register both the outline and
|
|
163
|
+
`-fill` files:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import favorite from "@material-symbols/svg-400/outlined/favorite.svg?component";
|
|
167
|
+
import favoriteFill from "@material-symbols/svg-400/outlined/favorite-fill.svg?component";
|
|
168
|
+
|
|
169
|
+
registerIcons({ favorite: { outline: favorite, fill: favoriteFill } });
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
> The `weight` and `grade` props are deprecated no-ops — static SVGs ship at
|
|
173
|
+
> weight 400, grade 0. `size`, `fill`, `inline`, and color (`currentColor`) work
|
|
174
|
+
> as before.
|
|
175
|
+
|
|
55
176
|
## Props
|
|
56
177
|
|
|
57
178
|
| Prop | Type | Required | Default |
|
package/components/Icon/Icon.vue
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { CSSProperties } from "vue";
|
|
3
3
|
import { computed } from "vue";
|
|
4
|
+
import { getIconComponent, warnMissingIcon } from "./registry";
|
|
5
|
+
import { registerDefaultIcons } from "./defaultIcons";
|
|
6
|
+
|
|
7
|
+
// Driven from setup (a retained code path) so the base set survives
|
|
8
|
+
// tree-shaking; idempotent, so the per-instance call is effectively free.
|
|
9
|
+
registerDefaultIcons();
|
|
4
10
|
|
|
5
11
|
export type IconSize = "sm" | "md" | "lg" | "xl";
|
|
6
12
|
|
|
@@ -8,7 +14,9 @@ interface Props {
|
|
|
8
14
|
icon: string;
|
|
9
15
|
size?: IconSize | number;
|
|
10
16
|
fill?: boolean;
|
|
17
|
+
/** @deprecated No effect — SVG icons ship at weight 400. */
|
|
11
18
|
weight?: number;
|
|
19
|
+
/** @deprecated No effect — SVG icons ship at grade 0. */
|
|
12
20
|
grade?: number;
|
|
13
21
|
decorative?: boolean;
|
|
14
22
|
ariaLabel?: string;
|
|
@@ -25,23 +33,17 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
25
33
|
const sizePreset = computed(() =>
|
|
26
34
|
typeof props.size === "string" ? props.size : undefined,
|
|
27
35
|
);
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
|
|
37
|
+
const inlineStyle = computed<CSSProperties>(() =>
|
|
38
|
+
typeof props.size === "number"
|
|
39
|
+
? { width: `${props.size}px`, height: `${props.size}px` }
|
|
40
|
+
: {},
|
|
30
41
|
);
|
|
31
42
|
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
(style as Record<string, unknown>)["--icon-opsz"] = numericSize.value;
|
|
37
|
-
}
|
|
38
|
-
if (props.weight !== undefined) {
|
|
39
|
-
(style as Record<string, unknown>)["--icon-weight"] = props.weight;
|
|
40
|
-
}
|
|
41
|
-
if (props.grade !== undefined) {
|
|
42
|
-
(style as Record<string, unknown>)["--icon-grade"] = props.grade;
|
|
43
|
-
}
|
|
44
|
-
return style;
|
|
43
|
+
const svg = computed(() => {
|
|
44
|
+
const component = getIconComponent(props.icon, props.fill);
|
|
45
|
+
if (!component) warnMissingIcon(props.icon);
|
|
46
|
+
return component;
|
|
45
47
|
});
|
|
46
48
|
</script>
|
|
47
49
|
|
|
@@ -49,64 +51,54 @@ const inlineStyle = computed<CSSProperties>(() => {
|
|
|
49
51
|
<span
|
|
50
52
|
class="Icon"
|
|
51
53
|
:data-size="sizePreset"
|
|
52
|
-
:data-fill="fill ? 'true' : undefined"
|
|
53
54
|
:data-inline="inline ? 'true' : undefined"
|
|
54
55
|
:style="inlineStyle"
|
|
55
56
|
:aria-hidden="decorative ? true : undefined"
|
|
56
57
|
:aria-label="decorative ? undefined : ariaLabel"
|
|
57
58
|
:role="decorative ? undefined : 'img'"
|
|
58
|
-
>{{ icon }}</span
|
|
59
59
|
>
|
|
60
|
+
<component :is="svg" v-if="svg" />
|
|
61
|
+
</span>
|
|
60
62
|
</template>
|
|
61
63
|
|
|
62
64
|
<style>
|
|
63
65
|
.Icon {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
text-transform: none;
|
|
71
|
-
display: inline-block;
|
|
72
|
-
white-space: nowrap;
|
|
73
|
-
word-wrap: normal;
|
|
74
|
-
direction: ltr;
|
|
75
|
-
font-feature-settings: "liga";
|
|
76
|
-
-webkit-font-smoothing: antialiased;
|
|
77
|
-
font-variation-settings:
|
|
78
|
-
"FILL" var(--icon-fill, 0),
|
|
79
|
-
"wght" var(--icon-weight, 400),
|
|
80
|
-
"GRAD" var(--icon-grade, 0),
|
|
81
|
-
"opsz" var(--icon-opsz, 24);
|
|
66
|
+
display: inline-flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
flex: none;
|
|
70
|
+
width: 24px;
|
|
71
|
+
height: 24px;
|
|
82
72
|
color: inherit;
|
|
83
73
|
}
|
|
84
74
|
|
|
75
|
+
.Icon svg {
|
|
76
|
+
display: block;
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
fill: currentColor;
|
|
80
|
+
}
|
|
81
|
+
|
|
85
82
|
.Icon[data-size="sm"] {
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
width: 20px;
|
|
84
|
+
height: 20px;
|
|
88
85
|
}
|
|
89
86
|
.Icon[data-size="md"] {
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
width: 24px;
|
|
88
|
+
height: 24px;
|
|
92
89
|
}
|
|
93
90
|
.Icon[data-size="lg"] {
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
width: 28px;
|
|
92
|
+
height: 28px;
|
|
96
93
|
}
|
|
97
94
|
.Icon[data-size="xl"] {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.Icon[data-fill="true"] {
|
|
103
|
-
--icon-fill: 1;
|
|
95
|
+
width: 32px;
|
|
96
|
+
height: 32px;
|
|
104
97
|
}
|
|
105
98
|
|
|
106
99
|
.Icon[data-inline="true"] {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
transform-origin: 50% 50%;
|
|
100
|
+
width: 1em;
|
|
101
|
+
height: 1em;
|
|
102
|
+
vertical-align: -0.125em;
|
|
111
103
|
}
|
|
112
104
|
</style>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// The base icon set, registered on first use of <Icon> so `icon="..."` works
|
|
2
|
+
// with zero setup. These are bundled into the published package (each import
|
|
3
|
+
// inlines a ~0.3-0.6 KB SVG at build time), so consumers need no install.
|
|
4
|
+
//
|
|
5
|
+
// Registration is driven from Icon.vue's setup (a used code path) rather than a
|
|
6
|
+
// bare side-effect import, so it survives tree-shaking of this side-effect-free
|
|
7
|
+
// package.
|
|
8
|
+
//
|
|
9
|
+
// Keep this list and the "Base set" table in Icon.md in sync.
|
|
10
|
+
import help from "@material-symbols/svg-400/outlined/help.svg?component";
|
|
11
|
+
import favorite from "@material-symbols/svg-400/outlined/favorite.svg?component";
|
|
12
|
+
import favorite_fill from "@material-symbols/svg-400/outlined/favorite-fill.svg?component";
|
|
13
|
+
import dark_mode from "@material-symbols/svg-400/outlined/dark_mode.svg?component";
|
|
14
|
+
import light_mode from "@material-symbols/svg-400/outlined/light_mode.svg?component";
|
|
15
|
+
// chevrons / navigation
|
|
16
|
+
import chevron_left from "@material-symbols/svg-400/outlined/chevron_left.svg?component";
|
|
17
|
+
import chevron_right from "@material-symbols/svg-400/outlined/chevron_right.svg?component";
|
|
18
|
+
import keyboard_arrow_up from "@material-symbols/svg-400/outlined/keyboard_arrow_up.svg?component";
|
|
19
|
+
import keyboard_arrow_down from "@material-symbols/svg-400/outlined/keyboard_arrow_down.svg?component";
|
|
20
|
+
import keyboard_double_arrow_left from "@material-symbols/svg-400/outlined/keyboard_double_arrow_left.svg?component";
|
|
21
|
+
import keyboard_double_arrow_right from "@material-symbols/svg-400/outlined/keyboard_double_arrow_right.svg?component";
|
|
22
|
+
// arrows (all directions)
|
|
23
|
+
import arrow_upward from "@material-symbols/svg-400/outlined/arrow_upward.svg?component";
|
|
24
|
+
import arrow_downward from "@material-symbols/svg-400/outlined/arrow_downward.svg?component";
|
|
25
|
+
import arrow_back from "@material-symbols/svg-400/outlined/arrow_back.svg?component";
|
|
26
|
+
import arrow_forward from "@material-symbols/svg-400/outlined/arrow_forward.svg?component";
|
|
27
|
+
// menus
|
|
28
|
+
import menu from "@material-symbols/svg-400/outlined/menu.svg?component";
|
|
29
|
+
import more_vert from "@material-symbols/svg-400/outlined/more_vert.svg?component";
|
|
30
|
+
import more_horiz from "@material-symbols/svg-400/outlined/more_horiz.svg?component";
|
|
31
|
+
// actions
|
|
32
|
+
import add from "@material-symbols/svg-400/outlined/add.svg?component";
|
|
33
|
+
import edit from "@material-symbols/svg-400/outlined/edit.svg?component";
|
|
34
|
+
import deleteIcon from "@material-symbols/svg-400/outlined/delete.svg?component";
|
|
35
|
+
import close from "@material-symbols/svg-400/outlined/close.svg?component";
|
|
36
|
+
import check from "@material-symbols/svg-400/outlined/check.svg?component";
|
|
37
|
+
import search from "@material-symbols/svg-400/outlined/search.svg?component";
|
|
38
|
+
import tune from "@material-symbols/svg-400/outlined/tune.svg?component";
|
|
39
|
+
import download from "@material-symbols/svg-400/outlined/download.svg?component";
|
|
40
|
+
// brand logos (not part of Material Symbols)
|
|
41
|
+
import github from "./github.svg?component";
|
|
42
|
+
import type { IconRegistration } from "./registry";
|
|
43
|
+
import { registerIcons, hasIcon } from "./registry";
|
|
44
|
+
|
|
45
|
+
const defaults: Record<string, IconRegistration> = {
|
|
46
|
+
// status / theme
|
|
47
|
+
help,
|
|
48
|
+
favorite: { outline: favorite, fill: favorite_fill },
|
|
49
|
+
dark_mode,
|
|
50
|
+
light_mode,
|
|
51
|
+
// chevrons / navigation
|
|
52
|
+
chevron_left,
|
|
53
|
+
chevron_right,
|
|
54
|
+
keyboard_arrow_up,
|
|
55
|
+
keyboard_arrow_down,
|
|
56
|
+
keyboard_double_arrow_left,
|
|
57
|
+
keyboard_double_arrow_right,
|
|
58
|
+
// arrows (all directions)
|
|
59
|
+
arrow_upward,
|
|
60
|
+
arrow_downward,
|
|
61
|
+
arrow_back,
|
|
62
|
+
arrow_forward,
|
|
63
|
+
// menus
|
|
64
|
+
menu,
|
|
65
|
+
more_vert,
|
|
66
|
+
more_horiz,
|
|
67
|
+
// actions
|
|
68
|
+
add,
|
|
69
|
+
edit,
|
|
70
|
+
delete: deleteIcon,
|
|
71
|
+
close,
|
|
72
|
+
check,
|
|
73
|
+
search,
|
|
74
|
+
tune,
|
|
75
|
+
download,
|
|
76
|
+
// brand logos
|
|
77
|
+
github,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
let registered = false;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Register the base icon set once. A name already registered by the consumer is
|
|
84
|
+
* left untouched, so explicit `registerIcons` calls always win over defaults.
|
|
85
|
+
*/
|
|
86
|
+
export function registerDefaultIcons(): void {
|
|
87
|
+
if (registered) return;
|
|
88
|
+
registered = true;
|
|
89
|
+
for (const [name, reg] of Object.entries(defaults)) {
|
|
90
|
+
if (!hasIcon(name)) registerIcons({ [name]: reg });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Component } from "vue";
|
|
2
|
+
|
|
3
|
+
/** A registered icon. Provide a bare component (outline only) or both variants. */
|
|
4
|
+
export interface IconVariants {
|
|
5
|
+
outline: Component;
|
|
6
|
+
fill?: Component;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type IconRegistration = Component | IconVariants;
|
|
10
|
+
|
|
11
|
+
const registry = new Map<string, IconVariants>();
|
|
12
|
+
|
|
13
|
+
function toVariants(reg: IconRegistration): IconVariants {
|
|
14
|
+
return typeof reg === "object" && reg !== null && "outline" in reg
|
|
15
|
+
? (reg as IconVariants)
|
|
16
|
+
: { outline: reg as Component };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Register icons for use with `<Icon icon="name" />`. Call once at app startup.
|
|
21
|
+
* Re-registering a name overwrites the previous entry.
|
|
22
|
+
*/
|
|
23
|
+
export function registerIcons(icons: Record<string, IconRegistration>): void {
|
|
24
|
+
for (const [name, reg] of Object.entries(icons)) {
|
|
25
|
+
registry.set(name, toVariants(reg));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Resolve the component for an icon name, preferring the fill variant when asked. */
|
|
30
|
+
export function getIconComponent(
|
|
31
|
+
name: string,
|
|
32
|
+
fill = false,
|
|
33
|
+
): Component | undefined {
|
|
34
|
+
const entry = registry.get(name);
|
|
35
|
+
if (!entry) return undefined;
|
|
36
|
+
return fill && entry.fill ? entry.fill : entry.outline;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Whether an icon name has been registered. */
|
|
40
|
+
export function hasIcon(name: string): boolean {
|
|
41
|
+
return registry.has(name);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const warned = new Set<string>();
|
|
45
|
+
|
|
46
|
+
function importSnippet(name: string): string {
|
|
47
|
+
const validIdent = /^[a-zA-Z_$][\w$]*$/.test(name);
|
|
48
|
+
const ident = validIdent ? name : `icon_${name.replace(/[^\w$]/g, "_")}`;
|
|
49
|
+
const reg = validIdent ? `{ ${name} }` : `{ "${name}": ${ident} }`;
|
|
50
|
+
return (
|
|
51
|
+
` import ${ident} from "@material-symbols/svg-400/outlined/${name}.svg?component";\n` +
|
|
52
|
+
` import { registerIcons } from "@cfasim-ui/components";\n` +
|
|
53
|
+
` registerIcons(${reg});`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Warn once per unregistered icon name with copy-pasteable registration code. */
|
|
58
|
+
export function warnMissingIcon(name: string): void {
|
|
59
|
+
if (warned.has(name)) return;
|
|
60
|
+
warned.add(name);
|
|
61
|
+
console.warn(
|
|
62
|
+
`[cfasim-ui] Icon "${name}" is not registered — nothing will render.\n` +
|
|
63
|
+
`Register it once at startup:\n\n` +
|
|
64
|
+
`${importSnippet(name)}\n\n` +
|
|
65
|
+
`Requires dev deps "@material-symbols/svg-400" + "vite-svg-loader".\n` +
|
|
66
|
+
`Docs: https://cdcgov.github.io/cfa-simulator/docs/cfasim-ui/components/icon#registering-icons`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -74,15 +74,18 @@ const isMac =
|
|
|
74
74
|
/Mac|iPhone|iPad/.test(navigator.platform);
|
|
75
75
|
const applyShortcut = isMac ? "⌘S" : "Ctrl+S";
|
|
76
76
|
|
|
77
|
-
// External value updates (e.g., parent Reset) re-seed the editor.
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
77
|
+
// External value updates (e.g., parent Reset) re-seed the editor. We
|
|
78
|
+
// compare against the last value we sourced from the parent — not
|
|
79
|
+
// against the live editor text — so a parent re-render that hands us a
|
|
80
|
+
// fresh object ref with the same contents doesn't clobber whatever the
|
|
81
|
+
// user is currently typing.
|
|
82
|
+
let lastSeeded = text.value;
|
|
81
83
|
watch(
|
|
82
84
|
() => props.value,
|
|
83
85
|
(v) => {
|
|
84
86
|
const next = serialize(v, format.value);
|
|
85
|
-
if (next ===
|
|
87
|
+
if (next === lastSeeded) return;
|
|
88
|
+
lastSeeded = next;
|
|
86
89
|
text.value = next;
|
|
87
90
|
error.value = "";
|
|
88
91
|
},
|
package/components/index.ts
CHANGED
|
@@ -8,6 +8,9 @@ export { default as Grid } from "./Grid/Grid.vue";
|
|
|
8
8
|
export type { GridCols, GridGap } from "./Grid/Grid.vue";
|
|
9
9
|
export { default as Hint } from "./Hint/Hint.vue";
|
|
10
10
|
export { default as Icon } from "./Icon/Icon.vue";
|
|
11
|
+
export type { IconSize } from "./Icon/Icon.vue";
|
|
12
|
+
export { registerIcons, hasIcon } from "./Icon/registry";
|
|
13
|
+
export type { IconRegistration, IconVariants } from "./Icon/registry";
|
|
11
14
|
export { default as LightDarkToggle } from "./LightDarkToggle/LightDarkToggle.vue";
|
|
12
15
|
export { default as NumberInput } from "./NumberInput/NumberInput.vue";
|
|
13
16
|
export type { NumberRange } from "./NumberInput/NumberInput.vue";
|
package/index.json
CHANGED