@cypress-design/vue-alert 0.0.2 → 0.1.2

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.
@@ -3,7 +3,7 @@ import dedent from 'dedent'
3
3
  import { ref } from 'vue'
4
4
  import Alert from './Alert.vue'
5
5
 
6
- export default (() => ({
6
+ export default () => ({
7
7
  setup() {
8
8
  const displayTimedAlert = ref(false)
9
9
  return () => (
@@ -107,4 +107,4 @@ export default (() => ({
107
107
  </div>
108
108
  )
109
109
  },
110
- }))()
110
+ })
package/Alert.stories.mdx CHANGED
@@ -17,7 +17,7 @@ import AlertStory from './Alert.rootstory'
17
17
 
18
18
  <Canvas withSource="none">
19
19
  <Story name="Alert">
20
- {AlertStory()}
20
+ {AlertStory}
21
21
  </Story>
22
22
  </Canvas>
23
23
 
package/Alert.vue CHANGED
@@ -1,15 +1,28 @@
1
1
  <template>
2
- <div v-if="!dismissed" class="overflow-hidden text-left" :class="props.notRounded ? undefined : 'rounded'">
2
+ <div
3
+ v-if="!dismissed"
4
+ class="overflow-hidden text-left"
5
+ :class="props.notRounded ? undefined : 'rounded'"
6
+ >
3
7
  <div class="flex p-16px" :class="typeClasses.headerClass">
4
8
  <!-- @slot replace the default left icon here -->
5
9
  <slot name="icon" v-bind="computedIconProps">
6
- <component v-if="!props.noIcon && icon" :is="icon" v-bind="computedIconProps" />
10
+ <component
11
+ v-if="!props.noIcon && icon"
12
+ :is="icon"
13
+ v-bind="computedIconProps"
14
+ />
7
15
  </slot>
8
16
  <div class="flex-1 font-medium">
9
17
  <!-- @slot title of the alert -->
10
18
  <slot />
11
19
  </div>
12
- <button v-if="dismissible" class="m-4px ml-8px h-16px" @click="dismiss" aria-label="Dismiss">
20
+ <button
21
+ v-if="dismissible"
22
+ class="m-4px ml-8px h-16px"
23
+ @click="dismiss"
24
+ aria-label="Dismiss"
25
+ >
13
26
  <IconActionDeleteLarge :stroke-color="typeClasses.iconCloseColor" />
14
27
  </button>
15
28
  </div>
@@ -17,26 +30,42 @@
17
30
  <!-- @slot body/details of the alert -->
18
31
  <slot name="body" />
19
32
  </div>
20
- <details v-if="slots.details" class="p-16px border-t-1" :class="[typeClasses.bodyClass, typeClasses.borderClass]">
21
- <summary class="flex font-medium cursor-pointer" :class="typeClasses.detailsHeaderClass">
22
- <IconChevronDownSmall :strokeColor="typeClasses.iconChevronColor" class="icon my-4px mr-8px" />
33
+ <details
34
+ v-if="slots.details"
35
+ class="p-16px border-t-1"
36
+ ref="detailsRef"
37
+ :class="[typeClasses.bodyClass, typeClasses.borderClass]"
38
+ >
39
+ <summary
40
+ class="flex font-medium cursor-pointer details-none"
41
+ :class="typeClasses.detailsHeaderClass"
42
+ >
43
+ <IconChevronDownSmall
44
+ :strokeColor="typeClasses.iconChevronColor"
45
+ class="icon my-4px mr-8px transition transform -rotate-90 open:rotate-0"
46
+ />
23
47
  {{ props.detailsTitle }}
24
48
  </summary>
25
- <div class="mt-16px">
26
- <!--@slot Togglable additional details-->
27
- <slot name="details" />
49
+ <div ref="contentRef">
50
+ <div class="mt-16px">
51
+ <!--@slot Togglable additional details-->
52
+ <slot name="details" />
53
+ </div>
28
54
  </div>
29
55
  </details>
30
56
  </div>
31
57
  </template>
32
58
 
33
59
  <script lang="ts" setup>
34
- import type { FunctionalComponent, ComputedRef } from 'vue';
60
+ import type { FunctionalComponent, ComputedRef } from 'vue'
35
61
  import { computed, useSlots, h, ref, onMounted, onUnmounted } from 'vue'
36
62
  import {
37
- IconChevronDownSmall, IconActionDeleteLarge,
38
- IconWarningCircle, IconCheckmarkOutline,
63
+ IconChevronDownSmall,
64
+ IconActionDeleteLarge,
65
+ IconWarningCircle,
66
+ IconCheckmarkOutline,
39
67
  } from '@cypress-design/vue-icon'
68
+ import { DetailsAnimation } from '@cypress-design/details-animation'
40
69
  import type { AlertType } from '../constants'
41
70
  import { alertClasses } from '../constants'
42
71
 
@@ -48,38 +77,44 @@ const emit = defineEmits<{
48
77
  /**
49
78
  * Clicking on the dismiss button or dismissed after a timeout
50
79
  */
51
- (event: 'dismiss'): void,
80
+ (event: 'dismiss'): void
52
81
  }>()
53
82
 
54
- const props = withDefaults(defineProps<{
55
- /**
56
- * Color scheme
57
- */
58
- type?: AlertType
59
- /**
60
- * If details are provided,text used in the toggle button
61
- */
62
- detailsTitle?: string
63
- /**
64
- * Show the dismiss button
65
- */
66
- dismissible?: boolean
67
- /**
68
- * When an icon is displayed by default, use this to remove it
69
- */
70
- noIcon?: boolean
71
- /**
72
- * If you need square corners
73
- */
74
- notRounded?: boolean
75
- /**
76
- * Dismiss the alert after a delay (in ms)
77
- */
78
- duration?: number
79
- }>(), {
80
- type: 'info',
81
- detailsTitle: 'Additional details',
82
- })
83
+ const props = withDefaults(
84
+ defineProps<{
85
+ /**
86
+ * Color scheme
87
+ */
88
+ type?: AlertType
89
+ /**
90
+ * If details are provided,text used in the toggle button
91
+ */
92
+ detailsTitle?: string
93
+ /**
94
+ * Show the dismiss button
95
+ */
96
+ dismissible?: boolean
97
+ /**
98
+ * When an icon is displayed by default, use this to remove it
99
+ */
100
+ noIcon?: boolean
101
+ /**
102
+ * If you need square corners
103
+ */
104
+ notRounded?: boolean
105
+ /**
106
+ * Dismiss the alert after a delay (in ms)
107
+ */
108
+ duration?: number
109
+ }>(),
110
+ {
111
+ type: 'info',
112
+ detailsTitle: 'Additional details',
113
+ }
114
+ )
115
+
116
+ const detailsRef = ref(null)
117
+ const contentRef = ref(null)
83
118
 
84
119
  const typeClasses = computed(() => {
85
120
  return alertClasses[props.type]
@@ -93,6 +128,12 @@ onMounted(() => {
93
128
  }
94
129
  })
95
130
 
131
+ onMounted(() => {
132
+ if (detailsRef.value && contentRef.value) {
133
+ new DetailsAnimation(detailsRef.value, contentRef.value)
134
+ }
135
+ })
136
+
96
137
  onUnmounted(() => {
97
138
  if (timeout) {
98
139
  clearTimeout(timeout)
@@ -111,14 +152,14 @@ function dismiss() {
111
152
  const computedIconProps = computed(() => {
112
153
  return {
113
154
  strokeColor: alertClasses[props.type].iconColor,
114
- class: 'my-4px mr-8px'
155
+ class: 'my-4px mr-8px',
115
156
  }
116
157
  })
117
158
 
118
159
  const icon: ComputedRef<FunctionalComponent | null> = computed(() => {
119
160
  switch (props.type) {
120
161
  case 'info':
121
- return null;
162
+ return null
122
163
  case 'success':
123
164
  return () => h(IconCheckmarkOutline, computedIconProps.value)
124
165
  case 'warning':
@@ -126,18 +167,7 @@ const icon: ComputedRef<FunctionalComponent | null> = computed(() => {
126
167
  case 'error':
127
168
  return () => h(IconWarningCircle, computedIconProps.value)
128
169
  default:
129
- return null;
170
+ return null
130
171
  }
131
172
  })
132
-
133
173
  </script>
134
-
135
- <style scoped>
136
- details summary .icon {
137
- transform: rotate(-90deg);
138
- }
139
-
140
- details[open] summary .icon {
141
- transform: rotate(0);
142
- }
143
- </style>
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @cypress-design/vue-alert
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#74](https://github.com/cypress-io/cypress-design/pull/74) [`6d8b6fd`](https://github.com/cypress-io/cypress-design/commit/6d8b6fd763b0389d748884c35f4ff6dd73724977) Thanks [@elevatebart](https://github.com/elevatebart)! - refactor to remove need for custom css
8
+
9
+ - Updated dependencies [[`6d8b6fd`](https://github.com/cypress-io/cypress-design/commit/6d8b6fd763b0389d748884c35f4ff6dd73724977)]:
10
+ - @cypress-design/details-animation@0.0.1
11
+
12
+ ## 0.1.1
13
+
14
+ ### Patch Changes
15
+
16
+ - [#68](https://github.com/cypress-io/cypress-design/pull/68) [`8c577fb`](https://github.com/cypress-io/cypress-design/commit/8c577fb0c6a0411cf8218dfe78281834df3d6f13) Thanks [@elevatebart](https://github.com/elevatebart)! - feat: publish `.mjs` files for esm intead of `.js`
17
+
18
+ - Updated dependencies [[`8c577fb`](https://github.com/cypress-io/cypress-design/commit/8c577fb0c6a0411cf8218dfe78281834df3d6f13)]:
19
+ - @cypress-design/vue-icon@0.5.2
20
+
21
+ ## 0.1.0
22
+
23
+ ### Minor Changes
24
+
25
+ - [#51](https://github.com/cypress-io/cypress-design/pull/51) [`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e) Thanks [@elevatebart](https://github.com/elevatebart)! - in the build asset, add a comment containing all used windicss classes in the component
26
+
27
+ ### Patch Changes
28
+
29
+ - [#46](https://github.com/cypress-io/cypress-design/pull/46) [`2608f59`](https://github.com/cypress-io/cypress-design/commit/2608f59e77f13ebdc25834309bf5d6390b37c350) Thanks [@elevatebart](https://github.com/elevatebart)! - fix alert story and details caret on webkit
30
+
31
+ * [#50](https://github.com/cypress-io/cypress-design/pull/50) [`1cb98e6`](https://github.com/cypress-io/cypress-design/commit/1cb98e6fc921e61e4645cdc9a60d48acb6d812c7) Thanks [@elevatebart](https://github.com/elevatebart)! - animate transition of details caret from closed to open
32
+
33
+ * Updated dependencies [[`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e), [`0866c65`](https://github.com/cypress-io/cypress-design/commit/0866c654f24c36951c98468d789462748606b428), [`43b53eb`](https://github.com/cypress-io/cypress-design/commit/43b53eb6bd10111629239a87374cfcc894eda0e3)]:
34
+ - @cypress-design/vue-icon@0.5.0
35
+
3
36
  ## 0.0.2
4
37
 
5
38
  ### Patch Changes
@@ -0,0 +1,219 @@
1
+ import { h as i, defineComponent as I, ref as x, useSlots as S, computed as z, onMounted as j, onUnmounted as $, openBlock as C, createElementBlock as f, normalizeClass as m, createElementVNode as p, unref as t, renderSlot as v, normalizeProps as A, guardReactiveProps as E, createBlock as H, resolveDynamicComponent as M, mergeProps as N, createCommentVNode as g, createVNode as D, createTextVNode as T, toDisplayString as B } from "vue";
2
+ import * as y from "@cypress-design/icon-registry";
3
+ import { ICON_COLOR_PROP_NAMES as O } from "@cypress-design/icon-registry";
4
+ import { DetailsAnimation as P } from "@cypress-design/details-animation";
5
+ const h = ({
6
+ body: s,
7
+ compiledClasses: e,
8
+ size: o,
9
+ class: r,
10
+ interactiveColorsOnGroup: k,
11
+ ...n
12
+ }) => {
13
+ const c = Object.keys(n).reduce((a, d) => (O.includes(d) || (a[d] = n[d]), a), {}), l = {
14
+ width: o,
15
+ height: o,
16
+ fill: "none",
17
+ innerHTML: s,
18
+ ...c
19
+ };
20
+ return e.length && (l.class = e.join(" ")), l;
21
+ }, V = (s) => {
22
+ const { sizeWithDefault: e, compiledClasses: o } = y.getComponentAttributes({ ...s, availableSizes: ["16"] }), r = {
23
+ 16: '<path d="M3 13 13 3M3 3l10 10" stroke="currentColor" class="icon-dark" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'
24
+ }[e];
25
+ if (!r)
26
+ throw Error(`Icon "action-delete-large" is not available in size ${e}`);
27
+ return i("svg", h({
28
+ ...s,
29
+ size: e,
30
+ body: r,
31
+ compiledClasses: o
32
+ }));
33
+ }, Z = (s) => {
34
+ const { sizeWithDefault: e, compiledClasses: o } = y.getComponentAttributes({ ...s, availableSizes: ["16"] }), r = {
35
+ 16: '<path d="M12.95 12.95a7 7 0 1 1-9.9-9.9 7 7 0 0 1 9.9 9.9Z" stroke="currentColor" stroke-width="2" class="icon-dark"/><path d="m6 8 1.5 2L10 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon-dark"/>'
36
+ }[e];
37
+ if (!r)
38
+ throw Error(`Icon "checkmark-outline" is not available in size ${e}`);
39
+ return i("svg", h({
40
+ ...s,
41
+ size: e,
42
+ body: r,
43
+ compiledClasses: o
44
+ }));
45
+ }, W = (s) => {
46
+ const { sizeWithDefault: e, compiledClasses: o } = y.getComponentAttributes({ ...s, availableSizes: ["8", "16"] }), r = {
47
+ 8: '<path d="m1 2.5 3 3 3-3" stroke="currentColor" class="icon-dark" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>',
48
+ 16: '<path d="m4 6 4 4 4-4" stroke="currentColor" class="icon-dark" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'
49
+ }[e];
50
+ if (!r)
51
+ throw Error(`Icon "chevron-down-small" is not available in size ${e}`);
52
+ return i("svg", h({
53
+ ...s,
54
+ size: e,
55
+ body: r,
56
+ compiledClasses: o
57
+ }));
58
+ }, R = (s) => {
59
+ const { sizeWithDefault: e, compiledClasses: o } = y.getComponentAttributes({ ...s, availableSizes: ["16"] }), r = {
60
+ 16: '<path fill-rule="evenodd" clip-rule="evenodd" d="M2 8a6 6 0 1 1 12 0A6 6 0 0 1 2 8Zm6-8a8 8 0 1 0 0 16A8 8 0 0 0 8 0Zm1 5a1 1 0 0 0-2 0v3a1 1 0 0 0 2 0V5Zm-1 7a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z" fill="currentColor" class="icon-dark"/>'
61
+ }[e];
62
+ if (!r)
63
+ throw Error(`Icon "warning-circle" is not available in size ${e}`);
64
+ return i("svg", h({
65
+ ...s,
66
+ size: e,
67
+ body: r,
68
+ compiledClasses: o
69
+ }));
70
+ }, _ = {
71
+ neutral: {
72
+ headerClass: "text-gray-800 bg-gray-100",
73
+ bodyClass: "bg-gray-50 text-gray-500",
74
+ borderClass: "border-gray-100",
75
+ detailsHeaderClass: "text-gray-600",
76
+ iconCloseColor: "gray-600",
77
+ iconColor: "gray-500",
78
+ iconChevronColor: "gray-300"
79
+ },
80
+ info: {
81
+ headerClass: "text-indigo-700 bg-indigo-100",
82
+ bodyClass: "bg-indigo-50 text-indigo-500",
83
+ borderClass: "border-indigo-100",
84
+ detailsHeaderClass: "text-indigo-600",
85
+ iconCloseColor: "indigo-500",
86
+ iconColor: "indigo-500",
87
+ iconChevronColor: "indigo-300"
88
+ },
89
+ warning: {
90
+ headerClass: "text-orange-700 bg-orange-100",
91
+ bodyClass: "bg-orange-50 text-orange-500",
92
+ borderClass: "border-orange-100",
93
+ detailsHeaderClass: "text-orange-600",
94
+ iconCloseColor: "orange-500",
95
+ iconColor: "orange-400",
96
+ iconChevronColor: "orange-300"
97
+ },
98
+ error: {
99
+ headerClass: "text-red-700 bg-red-100",
100
+ bodyClass: "bg-red-50 text-red-500",
101
+ borderClass: "border-red-100",
102
+ detailsHeaderClass: "text-red-600",
103
+ iconCloseColor: "red-500",
104
+ iconColor: "red-400",
105
+ iconChevronColor: "red-300"
106
+ },
107
+ success: {
108
+ headerClass: "text-jade-700 bg-jade-100",
109
+ bodyClass: "bg-jade-50 text-jade-600",
110
+ borderClass: "border-jade-100",
111
+ detailsHeaderClass: "text-jade-600",
112
+ iconCloseColor: "jade-600",
113
+ iconColor: "jade-500",
114
+ iconChevronColor: "jade-300"
115
+ }
116
+ }, L = { class: "flex-1 font-medium" }, G = { class: "mt-16px" }, K = /* @__PURE__ */ I({
117
+ __name: "Alert",
118
+ props: {
119
+ type: { default: "info" },
120
+ detailsTitle: { default: "Additional details" },
121
+ dismissible: { type: Boolean },
122
+ noIcon: { type: Boolean },
123
+ notRounded: { type: Boolean },
124
+ duration: null
125
+ },
126
+ emits: ["dismiss"],
127
+ setup(s, { emit: e }) {
128
+ const o = s, r = x(!1), k = S(), n = x(null), c = x(null), l = z(() => _[o.type]);
129
+ let a;
130
+ j(() => {
131
+ o.duration && (a = setTimeout(d, o.duration));
132
+ }), j(() => {
133
+ n.value && c.value && new P(n.value, c.value);
134
+ }), $(() => {
135
+ a && clearTimeout(a);
136
+ });
137
+ function d() {
138
+ r.value = !0, e("dismiss"), a && (clearTimeout(a), a = void 0);
139
+ }
140
+ const u = z(() => ({
141
+ strokeColor: _[o.type].iconColor,
142
+ class: "my-4px mr-8px"
143
+ })), w = z(() => {
144
+ switch (o.type) {
145
+ case "info":
146
+ return null;
147
+ case "success":
148
+ return () => i(Z, u.value);
149
+ case "warning":
150
+ return () => i(R, u.value);
151
+ case "error":
152
+ return () => i(R, u.value);
153
+ default:
154
+ return null;
155
+ }
156
+ });
157
+ return (b, U) => r.value ? g("", !0) : (C(), f("div", {
158
+ key: 0,
159
+ class: m(["overflow-hidden text-left", o.notRounded ? void 0 : "rounded"])
160
+ }, [
161
+ p("div", {
162
+ class: m(["flex p-16px", t(l).headerClass])
163
+ }, [
164
+ v(b.$slots, "icon", A(E(t(u))), () => [
165
+ !o.noIcon && t(w) ? (C(), H(M(t(w)), A(N({ key: 0 }, t(u))), null, 16)) : g("", !0)
166
+ ]),
167
+ p("div", L, [
168
+ v(b.$slots, "default")
169
+ ]),
170
+ s.dismissible ? (C(), f("button", {
171
+ key: 0,
172
+ class: "m-4px ml-8px h-16px",
173
+ onClick: d,
174
+ "aria-label": "Dismiss"
175
+ }, [
176
+ D(t(V), {
177
+ "stroke-color": t(l).iconCloseColor
178
+ }, null, 8, ["stroke-color"])
179
+ ])) : g("", !0)
180
+ ], 2),
181
+ t(k).body ? (C(), f("div", {
182
+ key: 0,
183
+ class: m(["p-16px", t(l).bodyClass])
184
+ }, [
185
+ v(b.$slots, "body")
186
+ ], 2)) : g("", !0),
187
+ t(k).details ? (C(), f("details", {
188
+ key: 1,
189
+ class: m(["p-16px border-t-1", [t(l).bodyClass, t(l).borderClass]]),
190
+ ref_key: "detailsRef",
191
+ ref: n
192
+ }, [
193
+ p("summary", {
194
+ class: m(["flex font-medium cursor-pointer details-none", t(l).detailsHeaderClass])
195
+ }, [
196
+ D(t(W), {
197
+ strokeColor: t(l).iconChevronColor,
198
+ class: "icon my-4px mr-8px transition transform -rotate-90 open:rotate-0"
199
+ }, null, 8, ["strokeColor"]),
200
+ T(" " + B(o.detailsTitle), 1)
201
+ ], 2),
202
+ p("div", {
203
+ ref_key: "contentRef",
204
+ ref: c
205
+ }, [
206
+ p("div", G, [
207
+ v(b.$slots, "details")
208
+ ])
209
+ ], 512)
210
+ ], 2)) : g("", !0)
211
+ ], 2));
212
+ }
213
+ });
214
+ export {
215
+ K as default
216
+ };
217
+
218
+ /* <windicss-keep class="overflow-hidden text-left rounded flex p-16px flex-1 font-medium m-4px ml-8px h-16px border-t-1 cursor-pointer details-none my-4px mr-8px transition transform -rotate-90 open:rotate-0 mt-16px text-gray-800 bg-gray-100 bg-gray-50 text-gray-500 border-gray-100 text-gray-600 text-indigo-700 bg-indigo-100 bg-indigo-50 text-indigo-500 border-indigo-100 text-indigo-600 text-orange-700 bg-orange-100 bg-orange-50 text-orange-500 border-orange-100 text-orange-600 text-red-700 bg-red-100 bg-red-50 text-red-500 border-red-100 text-red-600 text-jade-700 bg-jade-100 bg-jade-50 text-jade-600 border-jade-100 icon-dark-gray-600 icon-dark-gray-500 icon-dark-gray-300 icon-dark-indigo-500 icon-dark-indigo-300 icon-dark-orange-500 icon-dark-orange-400 icon-dark-orange-300 icon-dark-red-500 icon-dark-red-400 icon-dark-red-300 icon-dark-jade-600 icon-dark-jade-500 icon-dark-jade-300"> */
219
+ //# sourceMappingURL=index.es.mjs.map