@atomic-ui/ui-vue 0.2.0 → 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/README.md +54 -6
- package/dist/chunk-WM4MLN2U.js +27 -0
- package/dist/chunk-WM4MLN2U.js.map +1 -0
- package/dist/components.d.ts +516 -0
- package/dist/index.d.ts +22 -182
- package/dist/index.js +172 -72
- package/dist/index.js.map +1 -1
- package/dist/strata-components.d.ts +288 -0
- package/dist/strata.d.ts +20 -0
- package/dist/strata.js +131 -0
- package/dist/strata.js.map +1 -0
- package/dist/wrap.d.ts +32 -0
- package/package.json +22 -8
package/README.md
CHANGED
|
@@ -1,17 +1,65 @@
|
|
|
1
1
|
# @atomic-ui/ui-vue
|
|
2
2
|
|
|
3
|
-
Vue components for
|
|
3
|
+
Vue components for every `@atomic-ui/ui` custom element, and for every `@atomic-ui/strata` block in its `strata` entry. Arrays and objects are bound as DOM properties, props and events are typed, and every component and tag is in Vue's `GlobalComponents`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @atomic-ui/ui @atomic-ui/ui-vue
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Tell Vue's compiler that tags starting with `impakt-` are custom elements, in `vite.config.ts`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('impakt-') } } });
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then import the components where they are used:
|
|
16
|
+
|
|
17
|
+
```vue
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { ref } from 'vue';
|
|
20
|
+
import { ImpaktTable, ImpaktPagination, ImpaktTextInput } from '@atomic-ui/ui-vue';
|
|
21
|
+
|
|
22
|
+
const page = ref(1);
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<ImpaktTextInput label="Search cases" type="search" @change="(e) => (query = e.detail.value)" />
|
|
27
|
+
<ImpaktTable caption="Open cases" :columns="columns" :rows="rows" stack selectable @sort="(e) => sortBy(e.detail)" />
|
|
28
|
+
<ImpaktPagination :page="page" :pages="9" @page="(e) => (page = e.detail.page)" />
|
|
29
|
+
</template>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or register them all once with `app.use(AtomicUI)`, and write `<ImpaktTable>` anywhere.
|
|
33
|
+
|
|
34
|
+
Importing this package defines the elements, so nothing else needs importing first.
|
|
35
|
+
|
|
36
|
+
## The Strata blocks
|
|
37
|
+
|
|
38
|
+
The blocks Strata builds sites from are in `@atomic-ui/strata`, and their components are in this package's `strata` entry. An app that uses them installs that package too:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pnpm add @atomic-ui/ui @atomic-ui/strata @atomic-ui/ui-vue
|
|
42
|
+
```
|
|
4
43
|
|
|
5
44
|
```vue
|
|
6
45
|
<script setup lang="ts">
|
|
7
|
-
import '@atomic-ui/ui';
|
|
8
|
-
import { ImpktButton, ImpktHeading } from '@atomic-ui/ui-vue';
|
|
46
|
+
import { ImpaktHero, ImpaktCardGrid } from '@atomic-ui/ui-vue/strata';
|
|
9
47
|
</script>
|
|
10
48
|
|
|
11
49
|
<template>
|
|
12
|
-
<
|
|
13
|
-
<
|
|
50
|
+
<ImpaktHero heading="Homes made for the way you live" />
|
|
51
|
+
<ImpaktCardGrid :items="developments" columns="three" />
|
|
14
52
|
</template>
|
|
15
53
|
```
|
|
16
54
|
|
|
17
|
-
|
|
55
|
+
`app.use(AtomicUIStrata)` registers every block, and every block and its tag is in `GlobalComponents`. They are generated from `@atomic-ui/strata`'s manifest by the same script and named the same way. The main entry and `AtomicUI` hold the product components only, so an app that uses no blocks never loads them. `@atomic-ui/strata` is an optional peer dependency.
|
|
56
|
+
|
|
57
|
+
## Names
|
|
58
|
+
|
|
59
|
+
Each component is named after the element's class, so `impakt-table` is `ImpaktTable`. Each `impakt-` event is an emit without the prefix: `impakt-change` is `@change`, `impakt-sort` is `@sort` and `impakt-close` is `@close`, and the handler receives the event with its typed `detail`.
|
|
60
|
+
|
|
61
|
+
The components are generated from the component manifest when the package builds, by `scripts/generate.mjs`, so they always match the elements. The components 0.2.0 had keep their names, property bindings and emits.
|
|
62
|
+
|
|
63
|
+
## Writing the tags
|
|
64
|
+
|
|
65
|
+
A template can also write the tags, such as `<impakt-table :columns="columns" @impakt-sort="sortBy">`. They are typed through `GlobalComponents` as well. Bind arrays and objects with `:` as usual; Vue sets them as properties on a custom element.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// packages/ui-vue/src/wrap.ts
|
|
2
|
+
import { defineComponent, h } from "vue";
|
|
3
|
+
function wrap(tag, domProps = [], events = {}) {
|
|
4
|
+
return defineComponent({
|
|
5
|
+
name: tag.replace(/(^|-)(\w)/g, (_, __, c) => c.toUpperCase()),
|
|
6
|
+
inheritAttrs: false,
|
|
7
|
+
slots: Object,
|
|
8
|
+
setup(_, { attrs, slots, emit }) {
|
|
9
|
+
return () => {
|
|
10
|
+
const bound = {};
|
|
11
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
12
|
+
bound[domProps.includes(key) ? `.${key}` : key] = value;
|
|
13
|
+
}
|
|
14
|
+
for (const [eventName, vueName] of Object.entries(events)) {
|
|
15
|
+
bound[`on${eventName.replace(/(^|-)(\w)/g, (_2, __, c) => c.toUpperCase())}`] = (e) => emit(vueName, e);
|
|
16
|
+
}
|
|
17
|
+
return h(tag, bound, slots.default?.());
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
emits: Object.values(events)
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
wrap
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-WM4MLN2U.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/wrap.ts"],"sourcesContent":["import { defineComponent, h, type DefineSetupFnComponent, type SlotsType, type VNode } from 'vue';\n\ntype Props = Record<string, unknown>;\n\n/** The emits of a wrapper, from its events: `{ change: CustomEvent<…> }` gives a typed `@change`. */\ntype EmitsOf<Events> = { [K in keyof Events]: (event: Events[K]) => true };\n\n/**\n * A Vue component around one element, typed: its props are the element's own\n * properties, and attributes by their HTML names, and its events are typed emits.\n */\nexport type ImpaktComponent<E, K extends keyof E, Attributes extends string, Events> = DefineSetupFnComponent<\n { [P in K]?: E[P] } & { [A in Attributes]?: string | number | boolean },\n EmitsOf<Events>,\n SlotsType<{ default?: () => VNode[] }>\n>;\n\n/**\n * Build a Vue component around one element.\n *\n * `domProps` names the props that must be bound as properties rather than\n * attributes — anything that is not a string, a number or a boolean. Everything\n * else goes through as an attribute, which is what a custom element expects and\n * what keeps the rendered markup readable.\n */\nexport function wrap(tag: string, domProps: string[] = [], events: Record<string, string> = {}) {\n return defineComponent({\n name: tag.replace(/(^|-)(\\w)/g, (_, __, c: string) => c.toUpperCase()),\n inheritAttrs: false,\n slots: Object as SlotsType<{ default?: () => VNode[] }>,\n setup(_, { attrs, slots, emit }) {\n return () => {\n const bound: Props = {};\n for (const [key, value] of Object.entries(attrs)) {\n bound[domProps.includes(key) ? `.${key}` : key] = value;\n }\n for (const [eventName, vueName] of Object.entries(events)) {\n bound[`on${eventName.replace(/(^|-)(\\w)/g, (_, __, c: string) => c.toUpperCase())}`] =\n (e: Event) => emit(vueName, e);\n }\n return h(tag, bound, slots.default?.());\n };\n },\n emits: Object.values(events),\n });\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,SAAkE;AAyBrF,SAAS,KAAK,KAAa,WAAqB,CAAC,GAAG,SAAiC,CAAC,GAAG;AAC9F,SAAO,gBAAgB;AAAA,IACrB,MAAM,IAAI,QAAQ,cAAc,CAAC,GAAG,IAAI,MAAc,EAAE,YAAY,CAAC;AAAA,IACrE,cAAc;AAAA,IACd,OAAO;AAAA,IACP,MAAM,GAAG,EAAE,OAAO,OAAO,KAAK,GAAG;AAC/B,aAAO,MAAM;AACX,cAAM,QAAe,CAAC;AACtB,mBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,gBAAM,SAAS,SAAS,GAAG,IAAI,IAAI,GAAG,KAAK,GAAG,IAAI;AAAA,QACpD;AACA,mBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACzD,gBAAM,KAAK,UAAU,QAAQ,cAAc,CAACA,IAAG,IAAI,MAAc,EAAE,YAAY,CAAC,CAAC,EAAE,IACjF,CAAC,MAAa,KAAK,SAAS,CAAC;AAAA,QACjC;AACA,eAAO,EAAE,KAAK,OAAO,MAAM,UAAU,CAAC;AAAA,MACxC;AAAA,IACF;AAAA,IACA,OAAO,OAAO,OAAO,MAAM;AAAA,EAC7B,CAAC;AACH;","names":["_"]}
|