@citizenplane/pimp 12.0.1 → 12.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citizenplane/pimp",
3
- "version": "12.0.1",
3
+ "version": "12.0.3",
4
4
  "scripts": {
5
5
  "dev": "storybook dev -p 8080",
6
6
  "build-storybook": "storybook build --output-dir ./docs",
@@ -12,7 +12,7 @@
12
12
  --cp-drop-shadow-2xs-spread: -2px;
13
13
  --cp-drop-shadow-2xs-inset-spread: -1px;
14
14
  --cp-drop-shadow-xs-blur: 11px;
15
- --cp-drop-shadow-xs-color: var(--cp-colors-grey-shadow-color-12-5);
15
+ --cp-drop-shadow-xs-color: var(--cp-colors-grey-shadow-color-7-5);
16
16
  --cp-drop-shadow-xs-offset-x: 0;
17
17
  --cp-drop-shadow-xs-offset-y: 5px;
18
18
  --cp-drop-shadow-xs-spread: -2px;
@@ -8,7 +8,7 @@
8
8
  class="cpDialog__dialog"
9
9
  @keydown.esc.stop.prevent="handleClose"
10
10
  >
11
- <div aria-hidden="true" class="cpDialog__overlay" />
11
+ <div aria-hidden="true" class="cpDialog__overlay" :class="overlayDynamicClass" @click="handleOverlayClick" />
12
12
  <main ref="dialogContainer" class="cpDialog__container" :style="dynamicStyle" @keydown.tab="trapFocus">
13
13
  <header class="cpDialog__header">
14
14
  <div v-if="hasTitleOrSubtitle" class="cpDialog__headerTexts">
@@ -44,6 +44,7 @@ import { computed, ref, useSlots, onMounted, nextTick, onBeforeUnmount, useId }
44
44
  import { getKeyboardFocusableElements, handleTrapFocus } from '@/helpers/dom'
45
45
 
46
46
  interface Props {
47
+ isClosableOnClickOutside?: boolean
47
48
  maxWidth?: number
48
49
  subtitle?: string
49
50
  title?: string
@@ -57,6 +58,7 @@ const props = withDefaults(defineProps<Props>(), {
57
58
  maxWidth: 600,
58
59
  title: '',
59
60
  subtitle: '',
61
+ isClosableOnClickOutside: false,
60
62
  })
61
63
 
62
64
  const emit = defineEmits<Emits>()
@@ -74,6 +76,10 @@ const dialogContainer = ref<HTMLElement | null>(null)
74
76
 
75
77
  const dynamicStyle = computed(() => ({ maxWidth: `${props.maxWidth}px` }))
76
78
 
79
+ const overlayDynamicClass = computed(() => ({
80
+ 'cpDialog__overlay--isClosableOnClickOutside': props.isClosableOnClickOutside,
81
+ }))
82
+
77
83
  const hasTitleSlot = computed(() => !!slots.title)
78
84
  const hasTitle = computed(() => !!props.title || hasTitleSlot.value)
79
85
  const hasSubtitleSlot = computed(() => !!slots.subtitle)
@@ -96,6 +102,11 @@ const focusOnFirstFocusableElement = () => {
96
102
  focusableElements[0].focus()
97
103
  }
98
104
 
105
+ const handleOverlayClick = () => {
106
+ if (!props.isClosableOnClickOutside) return
107
+ handleClose()
108
+ }
109
+
99
110
  onMounted(() => {
100
111
  openDialog()
101
112
  nextTick(() => focusOnFirstFocusableElement())
@@ -146,11 +157,18 @@ $dialog-breakpoint: 550px;
146
157
  inset: 0;
147
158
  pointer-events: none;
148
159
  transition: opacity 250ms ease;
160
+
161
+ &--isClosableOnClickOutside {
162
+ pointer-events: auto;
163
+ z-index: 0;
164
+ cursor: pointer;
165
+ }
149
166
  }
150
167
 
151
168
  &__container {
152
169
  position: relative;
153
170
  display: flex;
171
+ z-index: 2;
154
172
  overflow: hidden;
155
173
  width: 100%;
156
174
  max-height: 100%;
@@ -131,3 +131,30 @@ export const TitleSubtitleWithSlots: Story = {
131
131
  `,
132
132
  }),
133
133
  }
134
+
135
+ export const ClosableOnClickOutside: Story = {
136
+ args: {
137
+ maxWidth: 600,
138
+ isClosableOnClickOutside: true,
139
+ },
140
+ render: (args) => ({
141
+ setup() {
142
+ const isOpen = ref(false)
143
+ return { args, isOpen }
144
+ },
145
+ template: `
146
+ <CpButton @click="isOpen = true">Open Dialog</CpButton>
147
+ <CpTransitionDialog>
148
+ <CpDialog v-bind="args" v-if="isOpen" @close="isOpen = false">
149
+ <template #title>Header slot</template>
150
+ <template #subtitle>Subtitle</template>
151
+ <p>This is the default slot content. You can put any content here.</p>
152
+ <template #footer>
153
+ <CpButton @click="isOpen = false">Cancel</CpButton>
154
+ This is the footer slot
155
+ </template>
156
+ </CpDialog>
157
+ </CpTransitionDialog>
158
+ `,
159
+ }),
160
+ }