@owocow/saber-ui 0.0.1
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 +72 -0
- package/dist/BadgeStatus.types.d.ts +10 -0
- package/dist/BadgeStatus.vue.d.ts +6 -0
- package/dist/colors.d.ts +10 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +74 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @owocow/saber-ui
|
|
2
|
+
|
|
3
|
+
Vue 3 component library — BadgeStatus and more, built on top of [@nuxt/ui](https://ui.nuxt.com).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @owocow/saber-ui @nuxt/ui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> Requires: `vue` ^3, `@nuxt/ui` ^4
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Plugin (recommended)
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// main.ts
|
|
19
|
+
import { createApp } from 'vue'
|
|
20
|
+
import App from './App.vue'
|
|
21
|
+
import SaberUI from '@owocow/saber-ui'
|
|
22
|
+
|
|
23
|
+
const app = createApp(App)
|
|
24
|
+
app.use(SaberUI)
|
|
25
|
+
app.mount('#app')
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<!-- Anywhere in your app -->
|
|
30
|
+
<template>
|
|
31
|
+
<BadgeStatus
|
|
32
|
+
:value="row.status"
|
|
33
|
+
:config="['闲置:0:green', '已预订:1:blue', '使用中:2:orange']"
|
|
34
|
+
/>
|
|
35
|
+
</template>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### On-demand import
|
|
39
|
+
|
|
40
|
+
```vue
|
|
41
|
+
<script setup>
|
|
42
|
+
import { BadgeStatus } from '@owocow/saber-ui'
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<BadgeStatus
|
|
47
|
+
:value="row.status"
|
|
48
|
+
:config="['闲置:0:green', '已预订:1:blue', '使用中:2:orange']"
|
|
49
|
+
/>
|
|
50
|
+
</template>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Components
|
|
54
|
+
|
|
55
|
+
### BadgeStatus
|
|
56
|
+
|
|
57
|
+
Status badge driven by `label:value:color` config. Renders `<UBadge>` from `@nuxt/ui`.
|
|
58
|
+
|
|
59
|
+
Colors use inline styles (hex → rgba) to avoid Tailwind v4 JIT dynamic-class issues.
|
|
60
|
+
|
|
61
|
+
#### Props
|
|
62
|
+
|
|
63
|
+
| Prop | Type | Default | Description |
|
|
64
|
+
|------|------|---------|-------------|
|
|
65
|
+
| `value` | `string \| number` | _(required)_ | Current value, matched against config's value segment |
|
|
66
|
+
| `config` | `string[]` | _(required)_ | `'label:value:color'` array, color = Tailwind color name (500/600 shades) |
|
|
67
|
+
| `bgOpacity` | `number` | `20` | Background opacity (0–100) |
|
|
68
|
+
| `textColorWeight` | `number` | `500` | Text color Tailwind shade |
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface BadgeStatusProps {
|
|
2
|
+
/** 当前值,与 config 中的 value 段匹配 */
|
|
3
|
+
value: string | number;
|
|
4
|
+
/** 'label:value:color' 格式的字符串数组,color 为 Tailwind 颜色名,如 ['闲置:0:green', '已预订:1:blue'] */
|
|
5
|
+
config: string[];
|
|
6
|
+
/** 背景色透明度(Tailwind opacity 数值),默认 20 */
|
|
7
|
+
bgOpacity?: number;
|
|
8
|
+
/** 文字颜色色阶权重(Tailwind 色阶),默认 500 */
|
|
9
|
+
textColorWeight?: number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BadgeStatusProps } from './BadgeStatus.types';
|
|
2
|
+
declare const _default: import('vue').DefineComponent<BadgeStatusProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<BadgeStatusProps> & Readonly<{}>, {
|
|
3
|
+
bgOpacity: number;
|
|
4
|
+
textColorWeight: number;
|
|
5
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
6
|
+
export default _default;
|
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tailwind 官方色系 500 / 600 色阶 hex 映射
|
|
3
|
+
*
|
|
4
|
+
* 用于替代动态模板字符串拼接类名,确保 Tailwind v4 JIT 扫描不受影响。
|
|
5
|
+
* 背景始终取 500 色阶 + rgba 透明度;文字取 textColorWeight 对应色阶。
|
|
6
|
+
*
|
|
7
|
+
* @see https://tailwindcss.com/docs/colors
|
|
8
|
+
*/
|
|
9
|
+
export declare function colorHex(color: string, shade: number): string;
|
|
10
|
+
export declare function hexToRgba(hex: string, opacity: number): string;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const b=require("@nuxt/ui/components/Badge.vue"),l=require("vue"),s={red:{500:"#ef4444",600:"#dc2626"},orange:{500:"#f97316",600:"#ea580c"},amber:{500:"#f59e0b",600:"#d97706"},yellow:{500:"#eab308",600:"#ca8a04"},lime:{500:"#84cc16",600:"#65a30d"},green:{500:"#22c55e",600:"#16a34a"},emerald:{500:"#10b981",600:"#059669"},teal:{500:"#14b8a6",600:"#0d9488"},cyan:{500:"#06b6d4",600:"#0891b2"},sky:{500:"#0ea5e9",600:"#0284c7"},blue:{500:"#3b82f6",600:"#2563eb"},indigo:{500:"#6366f1",600:"#4f46e5"},violet:{500:"#8b5cf6",600:"#7c3aed"},purple:{500:"#a855f7",600:"#9333ea"},fuchsia:{500:"#d946ef",600:"#c026d3"},pink:{500:"#ec4899",600:"#db2777"},rose:{500:"#f43f5e",600:"#e11d48"},slate:{500:"#64748b",600:"#475569"},gray:{500:"#6b7280",600:"#4b5563"},zinc:{500:"#71717a",600:"#52525b"},neutral:{500:"#737373",600:"#525252"},stone:{500:"#78716c",600:"#57534e"}},g=s.gray;function u(e,t){var o,c;return((o=s[e])==null?void 0:o[t])??((c=s[e])==null?void 0:c[500])??g[500]}function p(e,t){const o=parseInt(e.slice(1,3),16),c=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16);return`rgba(${o}, ${c}, ${a}, ${t/100})`}const d=l.defineComponent({__name:"BadgeStatus",props:{value:{},config:{},bgOpacity:{default:20},textColorWeight:{default:500}},setup(e){const t=e,o=l.computed(()=>{const a=String(t.value);for(const n of t.config){const[r,i,f]=n.split(":");if(i===a)return{label:r,color:f||"gray"}}return{label:a,color:"gray"}}),c=l.computed(()=>{const{color:a}=o.value,n=u(a,500),r=u(a,t.textColorWeight);return{backgroundColor:p(n,t.bgOpacity),color:r}});return(a,n)=>(l.openBlock(),l.createBlock(b,{style:l.normalizeStyle(c.value),variant:"soft",label:o.value.label,class:"rounded-full border-0 pt-0.75 pb-0.75 px-2"},null,8,["style","label"]))}}),y={install(e){e.component("UBadge",b),e.component("BadgeStatus",d)}};exports.BadgeStatus=d;exports.default=y;
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import u from "@nuxt/ui/components/Badge.vue";
|
|
2
|
+
import { defineComponent as f, computed as s, openBlock as g, createBlock as p, normalizeStyle as m } from "vue";
|
|
3
|
+
const l = {
|
|
4
|
+
red: { 500: "#ef4444", 600: "#dc2626" },
|
|
5
|
+
orange: { 500: "#f97316", 600: "#ea580c" },
|
|
6
|
+
amber: { 500: "#f59e0b", 600: "#d97706" },
|
|
7
|
+
yellow: { 500: "#eab308", 600: "#ca8a04" },
|
|
8
|
+
lime: { 500: "#84cc16", 600: "#65a30d" },
|
|
9
|
+
green: { 500: "#22c55e", 600: "#16a34a" },
|
|
10
|
+
emerald: { 500: "#10b981", 600: "#059669" },
|
|
11
|
+
teal: { 500: "#14b8a6", 600: "#0d9488" },
|
|
12
|
+
cyan: { 500: "#06b6d4", 600: "#0891b2" },
|
|
13
|
+
sky: { 500: "#0ea5e9", 600: "#0284c7" },
|
|
14
|
+
blue: { 500: "#3b82f6", 600: "#2563eb" },
|
|
15
|
+
indigo: { 500: "#6366f1", 600: "#4f46e5" },
|
|
16
|
+
violet: { 500: "#8b5cf6", 600: "#7c3aed" },
|
|
17
|
+
purple: { 500: "#a855f7", 600: "#9333ea" },
|
|
18
|
+
fuchsia: { 500: "#d946ef", 600: "#c026d3" },
|
|
19
|
+
pink: { 500: "#ec4899", 600: "#db2777" },
|
|
20
|
+
rose: { 500: "#f43f5e", 600: "#e11d48" },
|
|
21
|
+
slate: { 500: "#64748b", 600: "#475569" },
|
|
22
|
+
gray: { 500: "#6b7280", 600: "#4b5563" },
|
|
23
|
+
zinc: { 500: "#71717a", 600: "#52525b" },
|
|
24
|
+
neutral: { 500: "#737373", 600: "#525252" },
|
|
25
|
+
stone: { 500: "#78716c", 600: "#57534e" }
|
|
26
|
+
}, y = l.gray;
|
|
27
|
+
function b(e, t) {
|
|
28
|
+
var o, c;
|
|
29
|
+
return ((o = l[e]) == null ? void 0 : o[t]) ?? ((c = l[e]) == null ? void 0 : c[500]) ?? y[500];
|
|
30
|
+
}
|
|
31
|
+
function v(e, t) {
|
|
32
|
+
const o = parseInt(e.slice(1, 3), 16), c = parseInt(e.slice(3, 5), 16), a = parseInt(e.slice(5, 7), 16);
|
|
33
|
+
return `rgba(${o}, ${c}, ${a}, ${t / 100})`;
|
|
34
|
+
}
|
|
35
|
+
const x = /* @__PURE__ */ f({
|
|
36
|
+
__name: "BadgeStatus",
|
|
37
|
+
props: {
|
|
38
|
+
value: {},
|
|
39
|
+
config: {},
|
|
40
|
+
bgOpacity: { default: 20 },
|
|
41
|
+
textColorWeight: { default: 500 }
|
|
42
|
+
},
|
|
43
|
+
setup(e) {
|
|
44
|
+
const t = e, o = s(() => {
|
|
45
|
+
const a = String(t.value);
|
|
46
|
+
for (const n of t.config) {
|
|
47
|
+
const [r, d, i] = n.split(":");
|
|
48
|
+
if (d === a)
|
|
49
|
+
return { label: r, color: i || "gray" };
|
|
50
|
+
}
|
|
51
|
+
return { label: a, color: "gray" };
|
|
52
|
+
}), c = s(() => {
|
|
53
|
+
const { color: a } = o.value, n = b(a, 500), r = b(a, t.textColorWeight);
|
|
54
|
+
return {
|
|
55
|
+
backgroundColor: v(n, t.bgOpacity),
|
|
56
|
+
color: r
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
return (a, n) => (g(), p(u, {
|
|
60
|
+
style: m(c.value),
|
|
61
|
+
variant: "soft",
|
|
62
|
+
label: o.value.label,
|
|
63
|
+
class: "rounded-full border-0 pt-0.75 pb-0.75 px-2"
|
|
64
|
+
}, null, 8, ["style", "label"]));
|
|
65
|
+
}
|
|
66
|
+
}), k = {
|
|
67
|
+
install(e) {
|
|
68
|
+
e.component("UBadge", u), e.component("BadgeStatus", x);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
x as BadgeStatus,
|
|
73
|
+
k as default
|
|
74
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@owocow/saber-ui",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Vue 3 component library — BadgeStatus and more, built on top of @nuxt/ui",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "vite build",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@nuxt/ui": "^4",
|
|
25
|
+
"vue": "^3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@nuxt/ui": "^4",
|
|
29
|
+
"@vitejs/plugin-vue": "^5",
|
|
30
|
+
"typescript": "^5",
|
|
31
|
+
"vite": "^6",
|
|
32
|
+
"vite-plugin-dts": "^4",
|
|
33
|
+
"vue": "^3"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"vue",
|
|
37
|
+
"components",
|
|
38
|
+
"badge",
|
|
39
|
+
"status",
|
|
40
|
+
"nuxt-ui"
|
|
41
|
+
],
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/owocow/saber-ui"
|
|
49
|
+
}
|
|
50
|
+
}
|