@cypress-design/vue-alert 0.1.1 → 0.2.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.
@@ -3,29 +3,28 @@ import dedent from 'dedent'
3
3
  import { ref } from 'vue'
4
4
  import Alert from './Alert.vue'
5
5
 
6
- export default () => ({
7
- setup() {
8
- const displayTimedAlert = ref(false)
9
- return () => (
10
- <div class="flex flex-col p-4 gap-16px">
11
- <Alert type="error" detailsTitle="Stack trace" data-cy="alert-1">
12
- {{
13
- default: () => 'Spec not found',
14
- body: () => (
15
- <>
16
- There is no spec matching the following location:
17
- <code class="bg-red-100 m-8px rounded px-2px">
18
- path/to/spec.cy.js
19
- </code>
20
- <br />
21
- <br />
22
- It is possible that the file has since been moved or deleted.
23
- Please choose from the list of specs below
24
- </>
25
- ),
26
- details: () => (
27
- <pre class="bg-white rounded border border-red-500 px-16px py-8px overflow-x-auto">
28
- {dedent`Uncaught Error: Error occurred in defineConfig()
6
+ export default () => {
7
+ const displayTimedAlert = ref(false)
8
+ return (
9
+ <div class="flex flex-col p-4 gap-16px">
10
+ <Alert type="error" detailsTitle="Stack trace" data-cy="alert-1">
11
+ {{
12
+ default: () => 'Spec not found',
13
+ body: () => (
14
+ <>
15
+ There is no spec matching the following location:
16
+ <code class="bg-red-100 m-8px rounded px-2px">
17
+ path/to/spec.cy.js
18
+ </code>
19
+ <br />
20
+ <br />
21
+ It is possible that the file has since been moved or deleted.
22
+ Please choose from the list of specs below
23
+ </>
24
+ ),
25
+ details: () => (
26
+ <pre class="bg-white rounded border border-red-500 px-16px py-8px overflow-x-auto">
27
+ {dedent`Uncaught Error: Error occurred in defineConfig()
29
28
  Trace: add called with 2 and 3
30
29
  at sum (/home/dev/Documents/stacktrace.js:2:13)
31
30
  at start (/home/dev/Documents/stacktrace.js:11:13)
@@ -58,53 +57,68 @@ export default () => ({
58
57
  at Function.Module._load (internal/modules/cjs/loader.js:727:14)
59
58
  at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
60
59
  at internal/main/run_main_module.js:17:11`}
61
- </pre>
62
- ),
63
- }}
64
- </Alert>
65
- <button
66
- class="border rounded p-8px"
67
- onClick={() => (displayTimedAlert.value = true)}
60
+ </pre>
61
+ ),
62
+ }}
63
+ </Alert>
64
+ <button
65
+ class="border rounded p-8px"
66
+ onClick={() => (displayTimedAlert.value = true)}
67
+ >
68
+ open alert for 5 seconds
69
+ </button>
70
+ {displayTimedAlert.value && (
71
+ <Alert
72
+ duration={5000}
73
+ onDismiss={() => (displayTimedAlert.value = false)}
74
+ dismissible
75
+ data-cy="alert-2"
68
76
  >
69
- open alert for 5 seconds
70
- </button>
71
- {displayTimedAlert.value && (
72
- <Alert
73
- duration={5000}
74
- onDismiss={() => (displayTimedAlert.value = false)}
75
- dismissible
76
- data-cy="alert-2"
77
- >
78
- Wait 5 seconds please
79
- </Alert>
80
- )}
81
- <Alert type="success" dismissible data-cy="alert-3">
82
- {{
83
- default: () => 'Success with body',
84
- body: () => 'Success body',
85
- }}
86
- </Alert>
87
- <Alert type="warning" not-rounded>
88
- Warning
89
- </Alert>
90
- <Alert type="neutral">Neutral</Alert>
91
- <Alert type="error" dismissible class="text-justify" data-cy="alert-4">
92
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
93
- eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
94
- minim veniam, quis nostrud exercitation ullamco laboris nisi ut
95
- aliquip ex ea commodo consequat. Duis aute irure dolor in
96
- reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
97
- pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
98
- culpa qui officia deserunt mollit anim id est laborum.
77
+ Wait 5 seconds please
99
78
  </Alert>
100
- <Alert type="info">Info</Alert>
101
- <Alert type="info">
102
- {{
103
- default: () => 'Info',
104
- icon: (props: any) => <IconArrowRight {...props} />,
105
- }}
106
- </Alert>
107
- </div>
108
- )
109
- },
110
- })
79
+ )}
80
+ <Alert type="success" dismissible data-cy="alert-3">
81
+ {{
82
+ default: () => 'Success with body',
83
+ body: () => 'Success body',
84
+ }}
85
+ </Alert>
86
+ <Alert type="warning" not-rounded>
87
+ Warning
88
+ </Alert>
89
+ <Alert type="neutral">Neutral</Alert>
90
+ <Alert type="error" dismissible class="text-justify" data-cy="alert-4">
91
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
92
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
93
+ veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
94
+ commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
95
+ velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
96
+ occaecat cupidatat non proident, sunt in culpa qui officia deserunt
97
+ mollit anim id est laborum.
98
+ </Alert>
99
+ <Alert type="info">Info</Alert>
100
+ <Alert type="info">
101
+ {{
102
+ default: () => 'Info',
103
+ icon: (props: any) => <IconArrowRight {...props} />,
104
+ }}
105
+ </Alert>
106
+ {(['xs', 'sm', 'md', 'lg'] as const).map((size) => (
107
+ <>
108
+ <Alert type="error" data-cy="alert-size" size={size}>
109
+ {size} - Lorem ipsum dolor sit amet
110
+ </Alert>
111
+ <Alert type="warning" data-cy="alert-size" size={size}>
112
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
113
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
114
+ ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
115
+ aliquip ex ea commodo consequat. Duis aute irure dolor in
116
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
117
+ pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
118
+ culpa qui officia deserunt mollit anim id est laborum.
119
+ </Alert>
120
+ </>
121
+ ))}
122
+ </div>
123
+ )
124
+ }
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,43 +1,21 @@
1
- <template>
2
- <div v-if="!dismissed" class="overflow-hidden text-left" :class="props.notRounded ? undefined : 'rounded'">
3
- <div class="flex p-16px" :class="typeClasses.headerClass">
4
- <!-- @slot replace the default left icon here -->
5
- <slot name="icon" v-bind="computedIconProps">
6
- <component v-if="!props.noIcon && icon" :is="icon" v-bind="computedIconProps" />
7
- </slot>
8
- <div class="flex-1 font-medium">
9
- <!-- @slot title of the alert -->
10
- <slot />
11
- </div>
12
- <button v-if="dismissible" class="m-4px ml-8px h-16px" @click="dismiss" aria-label="Dismiss">
13
- <IconActionDeleteLarge :stroke-color="typeClasses.iconCloseColor" />
14
- </button>
15
- </div>
16
- <div v-if="slots.body" class="p-16px" :class="typeClasses.bodyClass">
17
- <!-- @slot body/details of the alert -->
18
- <slot name="body" />
19
- </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" />
23
- {{ props.detailsTitle }}
24
- </summary>
25
- <div class="mt-16px">
26
- <!--@slot Togglable additional details-->
27
- <slot name="details" />
28
- </div>
29
- </details>
30
- </div>
31
- </template>
32
-
33
1
  <script lang="ts" setup>
34
- import type { FunctionalComponent, ComputedRef } from 'vue';
2
+ import type { FunctionalComponent, ComputedRef } from 'vue'
35
3
  import { computed, useSlots, h, ref, onMounted, onUnmounted } from 'vue'
36
4
  import {
37
- IconChevronDownSmall, IconActionDeleteLarge,
38
- IconWarningCircle, IconCheckmarkOutline,
5
+ IconChevronDownSmall,
6
+ IconActionDeleteLarge,
7
+ IconWarningCircle,
8
+ IconCheckmarkOutline,
39
9
  } from '@cypress-design/vue-icon'
40
- import type { AlertType } from '../constants'
10
+ import { DetailsAnimation } from '@cypress-design/details-animation'
11
+ import {
12
+ AlertSize,
13
+ alertSizesClasses,
14
+ AlertType,
15
+ defaultAlertSize,
16
+ defaultAlertTitle,
17
+ defaultAlertType,
18
+ } from '../constants'
41
19
  import { alertClasses } from '../constants'
42
20
 
43
21
  const dismissed = ref(false)
@@ -48,38 +26,49 @@ const emit = defineEmits<{
48
26
  /**
49
27
  * Clicking on the dismiss button or dismissed after a timeout
50
28
  */
51
- (event: 'dismiss'): void,
29
+ (event: 'dismiss'): void
52
30
  }>()
53
31
 
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
- })
32
+ const props = withDefaults(
33
+ defineProps<{
34
+ /**
35
+ * Color scheme
36
+ */
37
+ type?: AlertType
38
+ /**
39
+ * If details are provided,text used in the toggle button
40
+ */
41
+ detailsTitle?: string
42
+ /**
43
+ * Show the dismiss button
44
+ */
45
+ dismissible?: boolean
46
+ /**
47
+ * When an icon is displayed by default, use this to remove it
48
+ */
49
+ noIcon?: boolean
50
+ /**
51
+ * If you need square corners
52
+ */
53
+ notRounded?: boolean
54
+ /**
55
+ * Dismiss the alert after a delay (in ms)
56
+ */
57
+ duration?: number
58
+ /**
59
+ * Size of the alert
60
+ */
61
+ size?: AlertSize
62
+ }>(),
63
+ {
64
+ type: defaultAlertType,
65
+ detailsTitle: defaultAlertTitle,
66
+ size: defaultAlertSize,
67
+ }
68
+ )
69
+
70
+ const detailsRef = ref(null)
71
+ const contentRef = ref(null)
83
72
 
84
73
  const typeClasses = computed(() => {
85
74
  return alertClasses[props.type]
@@ -93,6 +82,12 @@ onMounted(() => {
93
82
  }
94
83
  })
95
84
 
85
+ onMounted(() => {
86
+ if (detailsRef.value && contentRef.value) {
87
+ new DetailsAnimation(detailsRef.value, contentRef.value)
88
+ }
89
+ })
90
+
96
91
  onUnmounted(() => {
97
92
  if (timeout) {
98
93
  clearTimeout(timeout)
@@ -111,14 +106,14 @@ function dismiss() {
111
106
  const computedIconProps = computed(() => {
112
107
  return {
113
108
  strokeColor: alertClasses[props.type].iconColor,
114
- class: 'my-4px mr-8px'
109
+ class: 'my-4px mr-8px',
115
110
  }
116
111
  })
117
112
 
118
113
  const icon: ComputedRef<FunctionalComponent | null> = computed(() => {
119
114
  switch (props.type) {
120
115
  case 'info':
121
- return null;
116
+ return null
122
117
  case 'success':
123
118
  return () => h(IconCheckmarkOutline, computedIconProps.value)
124
119
  case 'warning':
@@ -126,23 +121,69 @@ const icon: ComputedRef<FunctionalComponent | null> = computed(() => {
126
121
  case 'error':
127
122
  return () => h(IconWarningCircle, computedIconProps.value)
128
123
  default:
129
- return null;
124
+ return null
130
125
  }
131
126
  })
132
127
 
128
+ const sizeClasses = computed(() => {
129
+ return alertSizesClasses[props.size]
130
+ })
133
131
  </script>
134
132
 
135
- <style scoped>
136
- details :deep(summary::-webkit-details-marker) {
137
- display: none;
138
- }
139
-
140
- details summary .icon {
141
- transform: rotate(-90deg);
142
- transition: transform 0.2s;
143
- }
144
-
145
- details[open] summary .icon {
146
- transform: rotate(0);
147
- }
148
- </style>
133
+ <template>
134
+ <div
135
+ v-if="!dismissed"
136
+ class="overflow-hidden text-left"
137
+ :class="props.notRounded ? undefined : 'rounded'"
138
+ >
139
+ <div class="flex" :class="[typeClasses.headerClass, sizeClasses]">
140
+ <!-- @slot replace the default left icon here -->
141
+ <slot name="icon" v-bind="computedIconProps">
142
+ <component
143
+ v-if="!props.noIcon && icon"
144
+ :is="icon"
145
+ v-bind="computedIconProps"
146
+ />
147
+ </slot>
148
+ <div class="flex-1 font-medium">
149
+ <!-- @slot title of the alert -->
150
+ <slot />
151
+ </div>
152
+ <button
153
+ v-if="dismissible"
154
+ class="m-4px ml-8px h-16px"
155
+ @click="dismiss"
156
+ aria-label="Dismiss"
157
+ >
158
+ <IconActionDeleteLarge :stroke-color="typeClasses.iconCloseColor" />
159
+ </button>
160
+ </div>
161
+ <div v-if="slots.body" class="p-16px" :class="typeClasses.bodyClass">
162
+ <!-- @slot body/details of the alert -->
163
+ <slot name="body" />
164
+ </div>
165
+ <details
166
+ v-if="slots.details"
167
+ class="p-16px border-t-1"
168
+ ref="detailsRef"
169
+ :class="[typeClasses.bodyClass, typeClasses.borderClass]"
170
+ >
171
+ <summary
172
+ class="flex font-medium cursor-pointer details-none"
173
+ :class="typeClasses.detailsHeaderClass"
174
+ >
175
+ <IconChevronDownSmall
176
+ :strokeColor="typeClasses.iconChevronColor"
177
+ class="icon my-4px mr-8px transition transform -rotate-90 open:rotate-0"
178
+ />
179
+ {{ props.detailsTitle }}
180
+ </summary>
181
+ <div ref="contentRef">
182
+ <div>
183
+ <!--@slot Togglable additional details-->
184
+ <slot name="details" />
185
+ </div>
186
+ </div>
187
+ </details>
188
+ </div>
189
+ </template>
package/AlertVue.cy.tsx CHANGED
@@ -4,6 +4,6 @@ import AlertStory from './Alert.rootstory'
4
4
 
5
5
  describe('<Alert />', { viewportHeight: 800 }, () => {
6
6
  it('renders', () => {
7
- mount(AlertStory)
7
+ mount(() => <AlertStory />)
8
8
  })
9
9
  })
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @cypress-design/vue-alert
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#114](https://github.com/cypress-io/cypress-design/pull/114) [`2a6597c`](https://github.com/cypress-io/cypress-design/commit/2a6597c16efc05ffe4ec51ab19cd2d7836a24c5c) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: add sizes to alerts
8
+
9
+ ## 0.1.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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
14
+
15
+ - Updated dependencies [[`6d8b6fd`](https://github.com/cypress-io/cypress-design/commit/6d8b6fd763b0389d748884c35f4ff6dd73724977)]:
16
+ - @cypress-design/details-animation@0.0.1
17
+
3
18
  ## 0.1.1
4
19
 
5
20
  ### Patch Changes
@@ -1,5 +1,13 @@
1
1
  import type { WindiColor } from '@cypress-design/icon-registry';
2
2
  export declare type AlertType = 'info' | 'success' | 'error' | 'warning' | 'neutral';
3
+ export declare const alertSizesClasses: {
4
+ readonly xs: "py-4px px-8px leading-22px text-14px";
5
+ readonly sm: "py-8px px-12px leading-22px text-14px";
6
+ readonly md: "py-12px px-16px leading-24px text-16px";
7
+ readonly lg: "p-16px leading-24px text-16px";
8
+ };
9
+ export declare type AlertSize = keyof typeof alertSizesClasses;
10
+ export declare const defaultAlertSize: AlertSize;
3
11
  export declare type AlertClasses = {
4
12
  headerClass: string;
5
13
  bodyClass: string;
@@ -10,4 +18,6 @@ export declare type AlertClasses = {
10
18
  iconChevronColor: WindiColor;
11
19
  };
12
20
  export declare const alertClasses: Record<AlertType, AlertClasses>;
21
+ export declare const defaultAlertType: AlertType;
22
+ export declare const defaultAlertTitle = "Additional details";
13
23
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/D,oBAAY,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAA;AAE5E,oBAAY,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,cAAc,EAAE,UAAU,CAAA;IAC1B,SAAS,CAAC,EAAE,UAAU,CAAA;IACtB,gBAAgB,EAAE,UAAU,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,CA6DxD,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/D,oBAAY,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAA;AAC5E,eAAO,MAAM,iBAAiB;;;;;CAKpB,CAAA;AAEV,oBAAY,SAAS,GAAG,MAAM,OAAO,iBAAiB,CAAA;AACtD,eAAO,MAAM,gBAAgB,EAAE,SAAgB,CAAA;AAE/C,oBAAY,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,cAAc,EAAE,UAAU,CAAA;IAC1B,SAAS,CAAC,EAAE,UAAU,CAAA;IACtB,gBAAgB,EAAE,UAAU,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,CA6DxD,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,SAAkB,CAAA;AAEjD,eAAO,MAAM,iBAAiB,uBAAuB,CAAA"}