@citizenplane/pimp 9.7.9 → 9.7.11
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/dist/pimp.es.js +708 -702
- package/dist/pimp.umd.js +9 -9
- package/package.json +1 -1
- package/src/components/CpToaster.vue +15 -4
- package/src/stories/CpToaster.stories.ts +52 -12
package/package.json
CHANGED
|
@@ -17,11 +17,16 @@
|
|
|
17
17
|
<p v-if="description" class="cpToaster__description">{{ description }}</p>
|
|
18
18
|
</div>
|
|
19
19
|
</div>
|
|
20
|
-
<button class="cpToaster__close" type="button" @click="closeToaster"
|
|
20
|
+
<button class="cpToaster__close" type="button" @click="closeToaster">
|
|
21
|
+
<cp-icon type="x" />
|
|
22
|
+
</button>
|
|
21
23
|
<div v-if="actionLabel" class="cpToaster__footer">
|
|
22
|
-
<button class="cpToaster__button" type="button" @click="handleActionMethod">
|
|
24
|
+
<button v-if="actionIsButton" class="cpToaster__button" type="button" @click="handleActionMethod">
|
|
23
25
|
{{ actionLabel }}
|
|
24
26
|
</button>
|
|
27
|
+
<a v-else class="cpToaster__button" v-bind="actionLinkProperties">
|
|
28
|
+
{{ actionLabel }}
|
|
29
|
+
</a>
|
|
25
30
|
</div>
|
|
26
31
|
</div>
|
|
27
32
|
</transition>
|
|
@@ -37,7 +42,9 @@ import CpIcon from '@/components/CpIcon.vue'
|
|
|
37
42
|
import { HeadingLevels, Intent } from '@/constants'
|
|
38
43
|
|
|
39
44
|
interface Props {
|
|
45
|
+
actionAs?: 'link' | 'button'
|
|
40
46
|
actionLabel?: string
|
|
47
|
+
actionLinkProperties?: Record<string, unknown>
|
|
41
48
|
actionMethod?: (vmProperties: Record<string, unknown>) => void
|
|
42
49
|
delayBeforeCloseInMs?: number
|
|
43
50
|
description?: string
|
|
@@ -55,6 +62,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
55
62
|
type: 'info',
|
|
56
63
|
delayBeforeCloseInMs: 5000,
|
|
57
64
|
actionLabel: '',
|
|
65
|
+
actionLinkProperties: () => ({}),
|
|
66
|
+
actionAs: 'button',
|
|
58
67
|
actionMethod: () => {},
|
|
59
68
|
isUnique: false,
|
|
60
69
|
})
|
|
@@ -78,6 +87,8 @@ const countDownInterval = ref<ReturnType<typeof setInterval>>()
|
|
|
78
87
|
|
|
79
88
|
const instance = getCurrentInstance()
|
|
80
89
|
|
|
90
|
+
const actionIsButton = computed(() => props.actionAs === 'button')
|
|
91
|
+
|
|
81
92
|
const toasterIcon = computed(() => {
|
|
82
93
|
const intentValues = Object.values(Intent)
|
|
83
94
|
const intent = intentValues.find((intentItem) => intentItem.value === props.type)
|
|
@@ -185,8 +196,8 @@ const closeToaster = (): void => {
|
|
|
185
196
|
}
|
|
186
197
|
|
|
187
198
|
const removeElement = (el: Element): void => {
|
|
188
|
-
if (typeof
|
|
189
|
-
|
|
199
|
+
if (typeof el.remove !== 'undefined') {
|
|
200
|
+
el.remove()
|
|
190
201
|
} else if (el.parentNode) {
|
|
191
202
|
el.parentNode.removeChild(el)
|
|
192
203
|
}
|
|
@@ -6,6 +6,15 @@ const meta = {
|
|
|
6
6
|
title: 'CpToaster',
|
|
7
7
|
component: CpToaster,
|
|
8
8
|
argTypes: {
|
|
9
|
+
actionAs: {
|
|
10
|
+
control: 'select',
|
|
11
|
+
options: ['link', 'button'],
|
|
12
|
+
description: 'Determines if the action is a link or a button',
|
|
13
|
+
},
|
|
14
|
+
actionLinkProperties: {
|
|
15
|
+
control: 'object',
|
|
16
|
+
description: 'Properties for the action link when actionAs is "link"',
|
|
17
|
+
},
|
|
9
18
|
title: {
|
|
10
19
|
control: 'text',
|
|
11
20
|
description: 'The title of the toast',
|
|
@@ -37,15 +46,17 @@ const meta = {
|
|
|
37
46
|
export default meta
|
|
38
47
|
type Story = StoryObj<typeof meta>
|
|
39
48
|
|
|
49
|
+
const defaultArgs = {
|
|
50
|
+
title: 'Default Toast',
|
|
51
|
+
description: 'This is a default toast message',
|
|
52
|
+
type: 'info',
|
|
53
|
+
delayBeforeCloseInMs: 3000,
|
|
54
|
+
actionLabel: '',
|
|
55
|
+
isUnique: false,
|
|
56
|
+
}
|
|
57
|
+
|
|
40
58
|
export const Default: Story = {
|
|
41
|
-
args:
|
|
42
|
-
title: 'Default Toast',
|
|
43
|
-
description: 'This is a default toast message',
|
|
44
|
-
type: 'info',
|
|
45
|
-
delayBeforeCloseInMs: 3000,
|
|
46
|
-
actionLabel: '',
|
|
47
|
-
isUnique: false,
|
|
48
|
-
},
|
|
59
|
+
args: defaultArgs,
|
|
49
60
|
render: (args) => ({
|
|
50
61
|
template: `
|
|
51
62
|
<div style="padding: 20px;">
|
|
@@ -61,6 +72,7 @@ export const Default: Story = {
|
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
export const DifferentTypes: Story = {
|
|
75
|
+
args: defaultArgs,
|
|
64
76
|
render: () => ({
|
|
65
77
|
template: `
|
|
66
78
|
<div style="padding: 20px; display: flex; flex-direction: column; gap: 16px;">
|
|
@@ -103,7 +115,35 @@ export const DifferentTypes: Story = {
|
|
|
103
115
|
}),
|
|
104
116
|
}
|
|
105
117
|
|
|
106
|
-
export const
|
|
118
|
+
export const WithActionAsLink: Story = {
|
|
119
|
+
args: defaultArgs,
|
|
120
|
+
render: () => ({
|
|
121
|
+
template: `
|
|
122
|
+
<div style="padding: 20px;">
|
|
123
|
+
<cp-button @click="addLinkToaster">Show Toast with Action</cp-button>
|
|
124
|
+
</div>
|
|
125
|
+
`,
|
|
126
|
+
methods: {
|
|
127
|
+
addLinkToaster() {
|
|
128
|
+
this.$toaster.success({
|
|
129
|
+
title: 'This is a success toaster',
|
|
130
|
+
description: 'Description of a toaster with a link',
|
|
131
|
+
actionAs: 'link',
|
|
132
|
+
actionLabel: 'See flight information',
|
|
133
|
+
actionLinkProperties: {
|
|
134
|
+
href: 'http://app.citizenplane.com',
|
|
135
|
+
target: '_blank',
|
|
136
|
+
rel: 'noopener noreferrer',
|
|
137
|
+
},
|
|
138
|
+
isUnique: true,
|
|
139
|
+
})
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const WithActionAsButton: Story = {
|
|
146
|
+
args: defaultArgs,
|
|
107
147
|
render: () => ({
|
|
108
148
|
template: `
|
|
109
149
|
<div style="padding: 20px;">
|
|
@@ -117,9 +157,8 @@ export const WithAction: Story = {
|
|
|
117
157
|
description: 'Description of a toaster with a link',
|
|
118
158
|
actionLabel: 'See flight information',
|
|
119
159
|
isUnique: true,
|
|
120
|
-
actionMethod: (
|
|
121
|
-
|
|
122
|
-
window.open('http://app.citizenplane.com', '_blank')
|
|
160
|
+
actionMethod: () => {
|
|
161
|
+
alert('Action button clicked!')
|
|
123
162
|
},
|
|
124
163
|
})
|
|
125
164
|
},
|
|
@@ -128,6 +167,7 @@ export const WithAction: Story = {
|
|
|
128
167
|
}
|
|
129
168
|
|
|
130
169
|
export const CustomDuration: Story = {
|
|
170
|
+
args: defaultArgs,
|
|
131
171
|
render: () => ({
|
|
132
172
|
template: `
|
|
133
173
|
<div style="padding: 20px;">
|