wshisbadboy-ui-lib 0.1.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.
@@ -0,0 +1,169 @@
1
+ <template>
2
+ <div
3
+ v-if="visible"
4
+ :class="['my-alert', `my-alert--${type}`]"
5
+ role="alert"
6
+ >
7
+ <span v-if="showIcon" class="my-alert__icon">
8
+ <slot name="icon">
9
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
10
+ <path v-if="type === 'success'" d="M22 11.08V12a10 10 0 11-5.93-9.14" />
11
+ <polyline v-if="type === 'success'" points="22 4 12 14.01 9 11.01" />
12
+ <path v-if="type === 'warning'" d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z" />
13
+ <line v-if="type === 'warning'" x1="12" y1="9" x2="12" y2="13" />
14
+ <line v-if="type === 'warning'" x1="12" y1="17" x2="12.01" y2="17" />
15
+ <circle v-if="type === 'error'" cx="12" cy="12" r="10" />
16
+ <line v-if="type === 'error'" x1="15" y1="9" x2="9" y2="15" />
17
+ <line v-if="type === 'error'" x1="9" y1="9" x2="15" y2="15" />
18
+ <circle v-if="type === 'info'" cx="12" cy="12" r="10" />
19
+ <line v-if="type === 'info'" x1="12" y1="16" x2="12" y2="12" />
20
+ <line v-if="type === 'info'" x1="12" y1="8" x2="12.01" y2="8" />
21
+ </svg>
22
+ </slot>
23
+ </span>
24
+ <div class="my-alert__body">
25
+ <span v-if="title || $slots.title" class="my-alert__title">
26
+ <slot name="title">{{ title }}</slot>
27
+ </span>
28
+ <p v-if="$slots.default || description" class="my-alert__desc">
29
+ <slot>{{ description }}</slot>
30
+ </p>
31
+ </div>
32
+ <button v-if="closable" class="my-alert__close" @click="close" aria-label="关闭">
33
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
34
+ <line x1="18" y1="6" x2="6" y2="18" />
35
+ <line x1="6" y1="6" x2="18" y2="18" />
36
+ </svg>
37
+ </button>
38
+ </div>
39
+ </template>
40
+
41
+ <script>
42
+ export default {
43
+ name: 'MyAlert',
44
+ }
45
+ </script>
46
+
47
+ <script setup>
48
+ import { ref } from 'vue'
49
+
50
+ const props = defineProps({
51
+ type: {
52
+ type: String,
53
+ default: 'info',
54
+ validator: (v) => ['info', 'success', 'warning', 'error'].includes(v),
55
+ },
56
+ title: { type: String, default: '' },
57
+ description: { type: String, default: '' },
58
+ closable: { type: Boolean, default: true },
59
+ showIcon: { type: Boolean, default: true },
60
+ })
61
+
62
+ const emit = defineEmits(['close'])
63
+
64
+ const visible = ref(true)
65
+
66
+ function close() {
67
+ visible.value = false
68
+ emit('close')
69
+ }
70
+ </script>
71
+
72
+ <style>
73
+ .my-alert {
74
+ display: flex;
75
+ align-items: flex-start;
76
+ gap: 10px;
77
+ padding: 12px 16px;
78
+ border-radius: 8px;
79
+ font-size: 14px;
80
+ line-height: 1.6;
81
+ position: relative;
82
+ border: 1px solid transparent;
83
+ }
84
+
85
+ /* ---- info ---- */
86
+ .my-alert--info {
87
+ background-color: #eff6ff;
88
+ border-color: #93c5fd;
89
+ color: #1e40af;
90
+ }
91
+ .my-alert--info .my-alert__desc {
92
+ color: #3b5998;
93
+ }
94
+
95
+ /* ---- success ---- */
96
+ .my-alert--success {
97
+ background-color: #f0fdf4;
98
+ border-color: #86efac;
99
+ color: #166534;
100
+ }
101
+ .my-alert--success .my-alert__desc {
102
+ color: #3a7d44;
103
+ }
104
+
105
+ /* ---- warning ---- */
106
+ .my-alert--warning {
107
+ background-color: #fffbeb;
108
+ border-color: #fcd34d;
109
+ color: #92400e;
110
+ }
111
+ .my-alert--warning .my-alert__desc {
112
+ color: #a16207;
113
+ }
114
+
115
+ /* ---- error ---- */
116
+ .my-alert--error {
117
+ background-color: #fef2f2;
118
+ border-color: #fca5a5;
119
+ color: #991b1b;
120
+ }
121
+ .my-alert--error .my-alert__desc {
122
+ color: #b91c1c;
123
+ }
124
+
125
+ .my-alert__icon {
126
+ display: inline-flex;
127
+ align-items: center;
128
+ flex-shrink: 0;
129
+ padding-top: 1px;
130
+ }
131
+
132
+ .my-alert__body {
133
+ flex: 1;
134
+ min-width: 0;
135
+ }
136
+
137
+ .my-alert__title {
138
+ display: block;
139
+ font-weight: 600;
140
+ margin-bottom: 2px;
141
+ }
142
+
143
+ .my-alert__desc {
144
+ margin: 0;
145
+ font-size: 13px;
146
+ }
147
+
148
+ .my-alert__close {
149
+ display: inline-flex;
150
+ align-items: center;
151
+ justify-content: center;
152
+ flex-shrink: 0;
153
+ width: 20px;
154
+ height: 20px;
155
+ border: none;
156
+ background: transparent;
157
+ color: inherit;
158
+ opacity: 0.6;
159
+ cursor: pointer;
160
+ border-radius: 4px;
161
+ transition: opacity 0.15s, background-color 0.15s;
162
+ padding: 0;
163
+ margin-top: 1px;
164
+ }
165
+ .my-alert__close:hover {
166
+ opacity: 1;
167
+ background-color: rgba(0, 0, 0, 0.06);
168
+ }
169
+ </style>
@@ -0,0 +1,7 @@
1
+ import Alert from './Alert.vue'
2
+
3
+ Alert.install = (app) => {
4
+ app.component(Alert.name, Alert)
5
+ }
6
+
7
+ export default Alert
@@ -0,0 +1,183 @@
1
+ <template>
2
+ <button
3
+ :class="[
4
+ 'my-btn',
5
+ `my-btn--${variant}`,
6
+ `my-btn--${size}`,
7
+ {
8
+ 'my-btn--loading': loading,
9
+ 'my-btn--icon-only': isIconOnly,
10
+ },
11
+ ]"
12
+ :disabled="disabled || loading"
13
+ :type="nativeType"
14
+ @click="handleClick"
15
+ >
16
+ <span v-if="loading" class="my-btn__loader"></span>
17
+ <span v-if="icon && !loading" class="my-btn__icon">
18
+ <slot name="icon">{{ icon }}</slot>
19
+ </span>
20
+ <span v-if="hasDefaultSlot && !isIconOnly" class="my-btn__text">
21
+ <slot />
22
+ </span>
23
+ </button>
24
+ </template>
25
+
26
+ <script>
27
+ export default {
28
+ name: 'MyButton',
29
+ }
30
+ </script>
31
+
32
+ <script setup>
33
+ import { useSlots, computed } from 'vue'
34
+
35
+ defineProps({
36
+ variant: {
37
+ type: String,
38
+ default: 'primary',
39
+ validator: (v) => ['primary', 'secondary', 'outline', 'text'].includes(v),
40
+ },
41
+ size: {
42
+ type: String,
43
+ default: 'medium',
44
+ validator: (v) => ['small', 'medium', 'large'].includes(v),
45
+ },
46
+ disabled: {
47
+ type: Boolean,
48
+ default: false,
49
+ },
50
+ loading: {
51
+ type: Boolean,
52
+ default: false,
53
+ },
54
+ nativeType: {
55
+ type: String,
56
+ default: 'button',
57
+ },
58
+ icon: {
59
+ type: String,
60
+ default: '',
61
+ },
62
+ })
63
+
64
+ const emit = defineEmits(['click'])
65
+ const slots = useSlots()
66
+ const hasDefaultSlot = computed(() => !!slots.default)
67
+ const isIconOnly = computed(() => !hasDefaultSlot.value)
68
+
69
+ function handleClick(e) {
70
+ emit('click', e)
71
+ }
72
+ </script>
73
+
74
+ <style>
75
+ .my-btn {
76
+ display: inline-flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ gap: 6px;
80
+ font-family: inherit;
81
+ font-weight: 500;
82
+ border: 1px solid transparent;
83
+ border-radius: 6px;
84
+ cursor: pointer;
85
+ transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
86
+ line-height: 1;
87
+ white-space: nowrap;
88
+ user-select: none;
89
+ }
90
+
91
+ .my-btn--small { padding: 6px 12px; font-size: 13px; min-height: 30px; }
92
+ .my-btn--medium { padding: 8px 18px; font-size: 14px; min-height: 36px; }
93
+ .my-btn--large { padding: 10px 24px; font-size: 16px; min-height: 42px; }
94
+
95
+ .my-btn--small.my-btn--icon-only { padding: 6px; width: 30px; }
96
+ .my-btn--medium.my-btn--icon-only { padding: 8px; width: 36px; }
97
+ .my-btn--large.my-btn--icon-only { padding: 10px; width: 42px; }
98
+
99
+ /* ---- primary ---- */
100
+ .my-btn--primary {
101
+ background-color: var(--my-primary);
102
+ color: #fff;
103
+ border-color: var(--my-primary);
104
+ }
105
+ .my-btn--primary:hover:not(:disabled) {
106
+ background-color: var(--my-primary-hover);
107
+ border-color: var(--my-primary-hover);
108
+ }
109
+ .my-btn--primary:active:not(:disabled) {
110
+ background-color: var(--my-primary-active);
111
+ }
112
+
113
+ /* ---- secondary ---- */
114
+ .my-btn--secondary {
115
+ background-color: var(--my-btn-secondary-bg);
116
+ color: var(--my-text);
117
+ border-color: var(--my-btn-secondary-border);
118
+ }
119
+ .my-btn--secondary:hover:not(:disabled) {
120
+ background-color: var(--my-btn-secondary-hover);
121
+ }
122
+ .my-btn--secondary:active:not(:disabled) {
123
+ background-color: var(--my-btn-secondary-active);
124
+ }
125
+
126
+ /* ---- outline ---- */
127
+ .my-btn--outline {
128
+ background-color: transparent;
129
+ color: var(--my-primary);
130
+ border-color: var(--my-primary);
131
+ }
132
+ .my-btn--outline:hover:not(:disabled) {
133
+ background-color: var(--my-primary-light);
134
+ }
135
+ .my-btn--outline:active:not(:disabled) {
136
+ background-color: var(--my-primary-lighter);
137
+ }
138
+
139
+ /* ---- text ---- */
140
+ .my-btn--text {
141
+ background-color: transparent;
142
+ color: var(--my-primary);
143
+ border-color: transparent;
144
+ }
145
+ .my-btn--text:hover:not(:disabled) {
146
+ background-color: var(--my-btn-text-hover);
147
+ }
148
+ .my-btn--text:active:not(:disabled) {
149
+ background-color: var(--my-btn-text-active);
150
+ }
151
+
152
+ /* ---- states ---- */
153
+ .my-btn:disabled {
154
+ opacity: 0.5;
155
+ cursor: not-allowed;
156
+ }
157
+
158
+ /* ---- loader ---- */
159
+ .my-btn__loader {
160
+ width: 14px;
161
+ height: 14px;
162
+ border: 2px solid currentColor;
163
+ border-right-color: transparent;
164
+ border-radius: 50%;
165
+ animation: my-btn-spin 0.6s linear infinite;
166
+ flex-shrink: 0;
167
+ }
168
+
169
+ @keyframes my-btn-spin {
170
+ to { transform: rotate(360deg); }
171
+ }
172
+
173
+ .my-btn__icon {
174
+ display: inline-flex;
175
+ align-items: center;
176
+ flex-shrink: 0;
177
+ }
178
+
179
+ .my-btn__text {
180
+ display: inline-flex;
181
+ align-items: center;
182
+ }
183
+ </style>
@@ -0,0 +1,7 @@
1
+ import Button from './Button.vue'
2
+
3
+ Button.install = (app) => {
4
+ app.component(Button.name, Button)
5
+ }
6
+
7
+ export default Button
@@ -0,0 +1,62 @@
1
+ <template>
2
+ <div class="my-collapse">
3
+ <slot />
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ name: 'MyCollapse',
10
+ }
11
+ </script>
12
+
13
+ <script setup>
14
+ import { provide, ref, watch } from 'vue'
15
+
16
+ const props = defineProps({
17
+ modelValue: {
18
+ type: Array,
19
+ default: () => [],
20
+ },
21
+ accordion: {
22
+ type: Boolean,
23
+ default: false,
24
+ },
25
+ })
26
+
27
+ const emit = defineEmits(['update:modelValue'])
28
+ const activeNames = ref([...props.modelValue])
29
+
30
+ watch(
31
+ () => props.modelValue,
32
+ (val) => {
33
+ activeNames.value = [...val]
34
+ },
35
+ )
36
+
37
+ provide('collapse', {
38
+ activeNames,
39
+ accordion: props.accordion,
40
+ onItemToggle(name) {
41
+ const idx = activeNames.value.indexOf(name)
42
+ if (idx > -1) {
43
+ activeNames.value.splice(idx, 1)
44
+ } else {
45
+ if (props.accordion) {
46
+ activeNames.value = [name]
47
+ } else {
48
+ activeNames.value.push(name)
49
+ }
50
+ }
51
+ emit('update:modelValue', [...activeNames.value])
52
+ },
53
+ })
54
+ </script>
55
+
56
+ <style>
57
+ .my-collapse {
58
+ border: 1px solid var(--my-border);
59
+ border-radius: 6px;
60
+ overflow: hidden;
61
+ }
62
+ </style>
@@ -0,0 +1,176 @@
1
+ <template>
2
+ <div
3
+ :class="['my-collapse-item', { 'is-active': isActive, 'is-disabled': disabled }]"
4
+ >
5
+ <button
6
+ class="my-collapse-item__header"
7
+ :disabled="disabled"
8
+ @click="toggle"
9
+ >
10
+ <span class="my-collapse-item__title">
11
+ <slot name="title">{{ title }}</slot>
12
+ </span>
13
+ <span class="my-collapse-item__arrow">
14
+ <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2">
15
+ <path d="M6 9l6 6 6-6" />
16
+ </svg>
17
+ </span>
18
+ </button>
19
+ <div class="my-collapse-item__wrap" :style="{ height: wrapHeight }">
20
+ <div class="my-collapse-item__content" ref="contentRef">
21
+ <slot />
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </template>
26
+
27
+ <script>
28
+ export default {
29
+ name: 'MyCollapseItem',
30
+ }
31
+ </script>
32
+
33
+ <script setup>
34
+ import { ref, inject, computed, onMounted, onBeforeUnmount, nextTick, watch } from 'vue'
35
+
36
+ const collapse = inject('collapse', null)
37
+
38
+ const props = defineProps({
39
+ title: { type: String, default: '' },
40
+ name: { type: [String, Number], required: true },
41
+ disabled: { type: Boolean, default: false },
42
+ })
43
+
44
+ const contentRef = ref(null)
45
+ const wrapHeight = ref('0')
46
+ let resizeObserver = null
47
+
48
+ const isActive = computed(() => {
49
+ if (!collapse) return false
50
+ return collapse.activeNames.value.includes(props.name)
51
+ })
52
+
53
+ function measureHeight() {
54
+ return contentRef.value ? contentRef.value.scrollHeight : 0
55
+ }
56
+
57
+ function toggle() {
58
+ if (props.disabled || !collapse) return
59
+ collapse.onItemToggle(props.name)
60
+ }
61
+
62
+ async function expand() {
63
+ wrapHeight.value = 'auto'
64
+ await nextTick()
65
+ const h = measureHeight()
66
+
67
+ wrapHeight.value = '0'
68
+ // force reflow
69
+ // eslint-disable-next-line no-unused-expressions
70
+ contentRef.value?.scrollHeight
71
+
72
+ requestAnimationFrame(() => {
73
+ wrapHeight.value = h + 'px'
74
+ })
75
+ }
76
+
77
+ function collapse_() {
78
+ const current = measureHeight()
79
+ wrapHeight.value = current + 'px'
80
+ requestAnimationFrame(() => {
81
+ requestAnimationFrame(() => {
82
+ wrapHeight.value = '0'
83
+ })
84
+ })
85
+ }
86
+
87
+ watch(isActive, (val) => {
88
+ if (val) {
89
+ expand()
90
+ } else {
91
+ collapse_()
92
+ }
93
+ })
94
+
95
+ onMounted(() => {
96
+ if (isActive.value) {
97
+ wrapHeight.value = 'auto'
98
+ }
99
+ if (contentRef.value) {
100
+ resizeObserver = new ResizeObserver(() => {
101
+ if (isActive.value && wrapHeight.value !== 'auto') {
102
+ const h = measureHeight()
103
+ if (h > 0) wrapHeight.value = h + 'px'
104
+ }
105
+ })
106
+ resizeObserver.observe(contentRef.value)
107
+ }
108
+ })
109
+
110
+ onBeforeUnmount(() => {
111
+ if (resizeObserver) resizeObserver.disconnect()
112
+ })
113
+ </script>
114
+
115
+ <style>
116
+ .my-collapse-item {
117
+ border-bottom: 1px solid var(--my-border);
118
+ }
119
+ .my-collapse-item:last-child {
120
+ border-bottom: none;
121
+ }
122
+
123
+ .my-collapse-item__header {
124
+ display: flex;
125
+ align-items: center;
126
+ justify-content: space-between;
127
+ width: 100%;
128
+ padding: 12px 16px;
129
+ border: none;
130
+ background: var(--my-bg);
131
+ font-size: 14px;
132
+ font-weight: 500;
133
+ color: var(--my-text);
134
+ cursor: pointer;
135
+ transition: background-color 0.15s;
136
+ line-height: 1.4;
137
+ text-align: left;
138
+ font-family: inherit;
139
+ }
140
+ .my-collapse-item__header:hover:not(:disabled) {
141
+ background-color: var(--my-bg-soft);
142
+ }
143
+ .my-collapse-item__header:disabled {
144
+ cursor: not-allowed;
145
+ opacity: 0.5;
146
+ }
147
+
148
+ .my-collapse-item__title {
149
+ flex: 1;
150
+ }
151
+
152
+ .my-collapse-item__arrow {
153
+ display: inline-flex;
154
+ flex-shrink: 0;
155
+ margin-left: 8px;
156
+ color: var(--my-text-muted);
157
+ transition: transform 0.3s;
158
+ }
159
+ .my-collapse-item.is-active .my-collapse-item__arrow {
160
+ transform: rotate(180deg);
161
+ }
162
+
163
+ .my-collapse-item__wrap {
164
+ overflow: hidden;
165
+ transition: height 0.3s ease;
166
+ background: var(--my-bg);
167
+ will-change: height;
168
+ }
169
+
170
+ .my-collapse-item__content {
171
+ padding: 0 16px 16px;
172
+ font-size: 14px;
173
+ color: var(--my-text-soft);
174
+ line-height: 1.6;
175
+ }
176
+ </style>
@@ -0,0 +1,12 @@
1
+ import Collapse from './Collapse.vue'
2
+ import CollapseItem from './CollapseItem.vue'
3
+
4
+ Collapse.install = (app) => {
5
+ app.component(Collapse.name, Collapse)
6
+ }
7
+ CollapseItem.install = (app) => {
8
+ app.component(CollapseItem.name, CollapseItem)
9
+ }
10
+
11
+ export { Collapse, CollapseItem }
12
+ export default Collapse