@operato/popup 2.0.0-beta.5 → 7.0.0-rc.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.
package/src/ox-prompt.ts CHANGED
@@ -1,4 +1,5 @@
1
- import '@material/web/button/elevated-button.js'
1
+ import '@material/web/button/filled-button.js'
2
+ import '@material/web/button/outlined-button.js'
2
3
  import '@material/web/icon/icon.js'
3
4
  import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'
4
5
 
@@ -163,6 +164,11 @@ export class OxPrompt extends LitElement {
163
164
  */
164
165
  @property({ type: Object }) cancelButton?: { text: string; color?: string }
165
166
 
167
+ /**
168
+ * Prevents the popup from closing when it loses focus (blur event).
169
+ */
170
+ @property({ type: Boolean, attribute: 'prevent-close-on-blur' }) preventCloseOnBlur: boolean = false
171
+
166
172
  /**
167
173
  * A callback function called when the popup is closed, providing the result of the user's interaction.
168
174
  */
@@ -187,14 +193,14 @@ export class OxPrompt extends LitElement {
187
193
  ${this.confirmButton
188
194
  ? html`
189
195
  <md-filled-button id="confirm" @click=${(e: Event) => this.onConfirm()}
190
- >${this.confirmButton?.text}</md-elevated-button
196
+ >${this.confirmButton?.text}</md-filled-button
191
197
  >
192
198
  `
193
199
  : nothing}
194
200
  ${this.cancelButton
195
201
  ? html`
196
202
  <md-outlined-button id="cancel" @click=${(e: Event) => this.onCancel()}
197
- >${this.cancelButton?.text}</md-elevated-button
203
+ >${this.cancelButton?.text}</md-outlined-button
198
204
  >
199
205
  `
200
206
  : nothing}
@@ -224,7 +230,7 @@ export class OxPrompt extends LitElement {
224
230
  if (!this.contains(to)) {
225
231
  /* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, ox-prompt은 닫혀야 한다. */
226
232
  // @ts-ignore for debug
227
- if (window.POPUP_DEBUG) {
233
+ if (this.preventCloseOnBlur || window.POPUP_DEBUG) {
228
234
  return
229
235
  }
230
236
 
@@ -279,7 +285,7 @@ export class OxPrompt extends LitElement {
279
285
 
280
286
  protected _onwindowblur: (e: Event) => void = function (this: OxPrompt, e: Event) {
281
287
  // @ts-ignore for debug
282
- if (window.POPUP_DEBUG) {
288
+ if (this.preventCloseOnBlur || window.POPUP_DEBUG) {
283
289
  return
284
290
  }
285
291
 
@@ -326,6 +332,7 @@ export class OxPrompt extends LitElement {
326
332
  * @param {string} [options.width] - The maximum width of the popup (CSS string).
327
333
  * @param {string} [options.height] - The maximum height of the popup (CSS string).
328
334
  * @param {Element | null} [options.parent] - The parent element to which the popup should be attached. If not provided, it will be attached to the document body.
335
+ * @param {boolean} [options.preventCloseOnBlur] - Prevents the popup from closing when it loses focus (blur event).
329
336
  * @param {(result: { value: boolean }) => void} [options.callback] - A callback function that will be invoked when the user interacts with the popup, providing the result of the interaction.
330
337
  * @returns {Promise<boolean>} A Promise that resolves based on user interaction with the popup.
331
338
  */
@@ -345,6 +352,7 @@ export class OxPrompt extends LitElement {
345
352
  width,
346
353
  height,
347
354
  parent,
355
+ preventCloseOnBlur,
348
356
  callback
349
357
  }: {
350
358
  template?: unknown
@@ -362,6 +370,7 @@ export class OxPrompt extends LitElement {
362
370
  width?: string
363
371
  height?: string
364
372
  parent?: Element | null
373
+ preventCloseOnBlur?: boolean
365
374
  callback?: (result: { value: boolean }) => void
366
375
  }): Promise<boolean> {
367
376
  const owner = parent || document.body
@@ -374,6 +383,7 @@ export class OxPrompt extends LitElement {
374
383
  target.footer = footer
375
384
  target.confirmButton = confirmButton
376
385
  target.cancelButton = cancelButton
386
+ target.preventCloseOnBlur = !!preventCloseOnBlur
377
387
 
378
388
  render(template, target)
379
389
 
@@ -6,12 +6,14 @@ import '../src/ox-popup-list.js'
6
6
  import { html, TemplateResult } from 'lit'
7
7
 
8
8
  import { OxPopupList } from '../src/ox-popup-list.js'
9
+ import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'
9
10
 
10
11
  export default {
11
12
  title: 'sortable OxPopupList',
12
13
  component: 'ox-popup-list',
13
14
  argTypes: {
14
- debug: { control: 'boolean' }
15
+ preventCloseOnBlur: { control: 'boolean' },
16
+ theme: { control: 'select', options: ['light', 'dark'] }
15
17
  }
16
18
  }
17
19
 
@@ -22,7 +24,8 @@ interface Story<T> {
22
24
  }
23
25
 
24
26
  interface ArgTypes {
25
- debug: boolean
27
+ preventCloseOnBlur: boolean
28
+ theme?: 'light' | 'dark'
26
29
  }
27
30
 
28
31
  function popup(e: MouseEvent) {
@@ -88,7 +91,13 @@ const columns = [
88
91
  }
89
92
  ]
90
93
 
91
- const Template: Story<ArgTypes> = ({ debug }: ArgTypes) => html`
94
+ const Template: Story<ArgTypes> = ({ preventCloseOnBlur, theme }: ArgTypes) => html`
95
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />
96
+
97
+ <link href="/themes/light.css" rel="stylesheet" />
98
+ <link href="/themes/dark.css" rel="stylesheet" />
99
+ <link href="/themes/spacing.css" rel="stylesheet" />
100
+
92
101
  <link
93
102
  href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
94
103
  rel="stylesheet"
@@ -102,6 +111,10 @@ const Template: Story<ArgTypes> = ({ debug }: ArgTypes) => html`
102
111
  rel="stylesheet"
103
112
  />
104
113
 
114
+ <style>
115
+ ${MDTypeScaleStyles.cssText}
116
+ </style>
117
+
105
118
  <style>
106
119
  #place {
107
120
  width: 100%;
@@ -109,6 +122,9 @@ const Template: Story<ArgTypes> = ({ debug }: ArgTypes) => html`
109
122
  background: lightgreen;
110
123
  text-align: center;
111
124
  line-height: 100px;
125
+
126
+ background-color: var(--md-sys-color-primary-container);
127
+ color: var(--md-sys-color-on-primary-container);
112
128
  }
113
129
 
114
130
  ox-popup-list {
@@ -160,6 +176,10 @@ const Template: Story<ArgTypes> = ({ debug }: ArgTypes) => html`
160
176
  }
161
177
  </style>
162
178
 
179
+ <script>
180
+ document.body.classList.add('${theme}')
181
+ </script>
182
+
163
183
  <div id="place" @click=${(e: MouseEvent) => popup(e)}>
164
184
  Click this to popup list
165
185
  <ox-popup-list
@@ -170,7 +190,7 @@ const Template: Story<ArgTypes> = ({ debug }: ArgTypes) => html`
170
190
  }}
171
191
  multiple
172
192
  sortable
173
- ?debug=${debug}
193
+ ?prevent-close-on-blur=${preventCloseOnBlur}
174
194
  >
175
195
  <div slot="header" titler>Plain Text <md-outlined-button>save</md-outlined-button></div>
176
196
  ${columns.map(
@@ -9,7 +9,7 @@ export default {
9
9
  component: 'ox-prompt',
10
10
  argTypes: {
11
11
  type: { control: 'select', options: ['success', 'error', 'warning', 'info', 'question'] },
12
- debug: { control: 'boolean' },
12
+ preventCloseOnBlur: { control: 'boolean' },
13
13
  theme: { control: 'select', options: ['light', 'dark'] }
14
14
  }
15
15
  }
@@ -22,7 +22,7 @@ interface Story<T> {
22
22
 
23
23
  interface ArgTypes {
24
24
  type: 'success' | 'error' | 'warning' | 'info' | 'question'
25
- debug: boolean
25
+ preventCloseOnBlur: boolean
26
26
  theme?: 'light' | 'dark'
27
27
  }
28
28
 
@@ -30,23 +30,22 @@ function popup(
30
30
  e: MouseEvent,
31
31
  type: 'success' | 'error' | 'warning' | 'info' | 'question' = 'warning',
32
32
  theme: 'light' | 'dark',
33
- debug: boolean
33
+ preventCloseOnBlur: boolean
34
34
  ) {
35
35
  const noImage = new URL('/assets/images/no-image.png', import.meta.url).href
36
36
 
37
- //@ts-ignore
38
- window.POPUP_DEBUG = debug
39
-
40
37
  OxPrompt.open({
41
38
  title: 'Are you sure ?',
42
39
  text: 'Are you sure to exit this page ?',
43
40
  type,
41
+ icon: noImage,
44
42
  confirmButton: { text: 'Confirm' },
45
- cancelButton: { text: 'Cancel' }
43
+ cancelButton: { text: 'Cancel' },
44
+ preventCloseOnBlur
46
45
  })
47
46
  }
48
47
 
49
- const Template: Story<ArgTypes> = ({ type, debug, theme = 'light' }: ArgTypes) => html`
48
+ const Template: Story<ArgTypes> = ({ type, preventCloseOnBlur, theme = 'light' }: ArgTypes) => html`
50
49
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />
51
50
 
52
51
  <link href="/themes/light.css" rel="stylesheet" />
@@ -85,7 +84,11 @@ const Template: Story<ArgTypes> = ({ type, debug, theme = 'light' }: ArgTypes) =
85
84
  document.body.classList.add('${theme}')
86
85
  </script>
87
86
 
88
- <div id="place" @click=${(e: MouseEvent) => popup(e, type, theme, debug)} class="md-typescale-display-medium">
87
+ <div
88
+ id="place"
89
+ @click=${(e: MouseEvent) => popup(e, type, theme, preventCloseOnBlur)}
90
+ class="md-typescale-display-medium"
91
+ >
89
92
  Click this to prompt image
90
93
  </div>
91
94
  `
@@ -93,5 +96,5 @@ const Template: Story<ArgTypes> = ({ type, debug, theme = 'light' }: ArgTypes) =
93
96
  export const Regular = Template.bind({})
94
97
  Regular.args = {
95
98
  type: 'warning',
96
- debug: true
99
+ preventCloseOnBlur: true
97
100
  }
@@ -48,11 +48,9 @@ body {
48
48
  --grid-record-wide-fontsize: var(--md-sys-typescale-label-medium-size);
49
49
  --grid-record-selected-background-color: var(--md-sys-color-primary-container);
50
50
  --grid-record-selected-color: var(--md-sys-color-primary);
51
- --grid-record-focused-background-color: var(--md-sys-color-secondary-container);
52
51
  --grid-record-focused-border: 1px solid var(--md-sys-color-outline-variant);
53
52
  --grid-record-focused-cell-background-color: var(--md-sys-color-secondary-container);
54
53
  --grid-record-focused-cell-border: 1px dashed var(--md-sys-color-outline);
55
- --grid-record-focused-color: var(--md-sys-color-secondary);
56
54
  --grid-record-focused-box-shadow: 0px 2px 0px 0px rgb(0 0 0 / 10%);
57
55
  --grid-record-emphasized-background-color: var(--md-sys-color-tertiary-container);
58
56
  --grid-record-emphasized-color: var(--md-sys-color-tertiary);