maz-ui 5.0.0 → 5.1.0-beta.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/dist/assets/{MazDropzone.DJ8au25t.css → MazDropzone.BW2grpTi.css} +1 -1
- package/dist/chunks/{MazDrawer.DANxKYxJ.js → MazDrawer.CC8zomfx.js} +2 -2
- package/dist/chunks/{MazDropzone.POH3pmfi.js → MazDropzone.Dez5j0WP.js} +2 -2
- package/dist/components/MazDrawer.js +1 -1
- package/dist/components/MazDropzone.js +1 -1
- package/dist/components/MazDropzone.vue.d.ts +2 -2
- package/dist/components/MazInputPrice.vue.d.ts +1 -1
- package/dist/components/index.js +2 -2
- package/docs/README.md +207 -0
- package/docs/agents/agents-md.md +52 -0
- package/docs/agents/claude-rule.md +52 -0
- package/docs/components/maz-accordion.md +76 -0
- package/docs/components/maz-alert.md +241 -0
- package/docs/components/maz-animated-counter.md +87 -0
- package/docs/components/maz-animated-element.md +46 -0
- package/docs/components/maz-animated-text.md +53 -0
- package/docs/components/maz-avatar.md +193 -0
- package/docs/components/maz-backdrop.md +178 -0
- package/docs/components/maz-badge.md +167 -0
- package/docs/components/maz-bottom-sheet.md +257 -0
- package/docs/components/maz-btn-group.md +316 -0
- package/docs/components/maz-btn.md +423 -0
- package/docs/components/maz-card-spotlight.md +84 -0
- package/docs/components/maz-card.md +321 -0
- package/docs/components/maz-carousel.md +153 -0
- package/docs/components/maz-chart.md +206 -0
- package/docs/components/maz-checkbox.md +138 -0
- package/docs/components/maz-checklist.md +251 -0
- package/docs/components/maz-circular-progress-bar.md +109 -0
- package/docs/components/maz-code-highlight.md +155 -0
- package/docs/components/maz-container.md +241 -0
- package/docs/components/maz-date-picker.md +791 -0
- package/docs/components/maz-dialog-confirm.md +215 -0
- package/docs/components/maz-dialog.md +143 -0
- package/docs/components/maz-drawer.md +106 -0
- package/docs/components/maz-dropdown.md +419 -0
- package/docs/components/maz-dropzone.md +387 -0
- package/docs/components/maz-expand-animation.md +82 -0
- package/docs/components/maz-fullscreen-loader.md +58 -0
- package/docs/components/maz-gallery.md +79 -0
- package/docs/components/maz-icon.md +203 -0
- package/docs/components/maz-input-code.md +73 -0
- package/docs/components/maz-input-number.md +79 -0
- package/docs/components/maz-input-phone-number.md +536 -0
- package/docs/components/maz-input-price.md +68 -0
- package/docs/components/maz-input-tags.md +112 -0
- package/docs/components/maz-input.md +334 -0
- package/docs/components/maz-lazy-img.md +113 -0
- package/docs/components/maz-link.md +146 -0
- package/docs/components/maz-loading-bar.md +38 -0
- package/docs/components/maz-markdown-editor.md +320 -0
- package/docs/components/maz-pagination.md +82 -0
- package/docs/components/maz-popover.md +794 -0
- package/docs/components/maz-pull-to-refresh.md +222 -0
- package/docs/components/maz-radio-buttons.md +313 -0
- package/docs/components/maz-radio.md +119 -0
- package/docs/components/maz-read-more.md +209 -0
- package/docs/components/maz-reading-progress-bar.md +96 -0
- package/docs/components/maz-select-country.md +513 -0
- package/docs/components/maz-select.md +318 -0
- package/docs/components/maz-sidebar-content.md +25 -0
- package/docs/components/maz-sidebar-footer.md +25 -0
- package/docs/components/maz-sidebar-group.md +27 -0
- package/docs/components/maz-sidebar-header.md +25 -0
- package/docs/components/maz-sidebar-menu-button.md +41 -0
- package/docs/components/maz-sidebar-menu-item.md +25 -0
- package/docs/components/maz-sidebar-menu-sub.md +32 -0
- package/docs/components/maz-sidebar-menu.md +25 -0
- package/docs/components/maz-sidebar-separator.md +21 -0
- package/docs/components/maz-sidebar-trigger.md +25 -0
- package/docs/components/maz-sidebar.md +507 -0
- package/docs/components/maz-skeleton.md +226 -0
- package/docs/components/maz-slider.md +165 -0
- package/docs/components/maz-spinner.md +84 -0
- package/docs/components/maz-stepper.md +301 -0
- package/docs/components/maz-switch.md +86 -0
- package/docs/components/maz-table-cell.md +27 -0
- package/docs/components/maz-table-row.md +28 -0
- package/docs/components/maz-table-title.md +27 -0
- package/docs/components/maz-table-virtualizer.md +31 -0
- package/docs/components/maz-table.md +426 -0
- package/docs/components/maz-tabs-bar.md +43 -0
- package/docs/components/maz-tabs-content-item.md +27 -0
- package/docs/components/maz-tabs-content.md +27 -0
- package/docs/components/maz-tabs.md +308 -0
- package/docs/components/maz-textarea.md +255 -0
- package/docs/components/maz-ticker.md +427 -0
- package/docs/components/maz-timeline.md +304 -0
- package/docs/components/maz-ui-provider.md +26 -0
- package/docs/components/maz-window-mockup.md +182 -0
- package/docs/composables/use-aos.md +41 -0
- package/docs/composables/use-breakpoints.md +42 -0
- package/docs/composables/use-dialog.md +58 -0
- package/docs/composables/use-display-names.md +130 -0
- package/docs/composables/use-drag.md +185 -0
- package/docs/composables/use-form-validator.md +1123 -0
- package/docs/composables/use-idle-timeout.md +172 -0
- package/docs/composables/use-pull-to-refresh.md +86 -0
- package/docs/composables/use-reading-time.md +132 -0
- package/docs/composables/use-string-matching.md +41 -0
- package/docs/composables/use-swipe.md +171 -0
- package/docs/composables/use-timer.md +104 -0
- package/docs/composables/use-toast.md +50 -0
- package/docs/composables/use-user-visibility.md +127 -0
- package/docs/composables/use-wait.md +50 -0
- package/docs/composables/use-window-size.md +25 -0
- package/docs/directives/click-outside.md +182 -0
- package/docs/directives/fullscreen-img.md +83 -0
- package/docs/directives/lazy-img.md +182 -0
- package/docs/directives/tooltip.md +298 -0
- package/docs/directives/zoom-img.md +100 -0
- package/docs/ecosystem/eslint-config.md +289 -0
- package/docs/ecosystem/icons/icon-set.md +25 -0
- package/docs/ecosystem/icons/index.md +584 -0
- package/docs/ecosystem/mcp.md +165 -0
- package/docs/ecosystem/node/exec-promise.md +93 -0
- package/docs/ecosystem/node/index.md +53 -0
- package/docs/ecosystem/node/logger.md +152 -0
- package/docs/ecosystem/node/print-banner.md +101 -0
- package/docs/ecosystem/node/setup-agents.md +102 -0
- package/docs/ecosystem/nuxt.md +551 -0
- package/docs/ecosystem/stylelint-config.md +310 -0
- package/docs/ecosystem/themes.md +966 -0
- package/docs/ecosystem/translations.md +1173 -0
- package/docs/ecosystem/utils/camel-case.md +37 -0
- package/docs/ecosystem/utils/capitalize.md +37 -0
- package/docs/ecosystem/utils/check-availability.md +85 -0
- package/docs/ecosystem/utils/cookie.md +86 -0
- package/docs/ecosystem/utils/country-code-to-unicode-flag.md +128 -0
- package/docs/ecosystem/utils/currency.md +53 -0
- package/docs/ecosystem/utils/date.md +53 -0
- package/docs/ecosystem/utils/debounce-callback.md +44 -0
- package/docs/ecosystem/utils/debounce-id.md +75 -0
- package/docs/ecosystem/utils/debounce.md +71 -0
- package/docs/ecosystem/utils/fetch-locale-ip.md +39 -0
- package/docs/ecosystem/utils/format-json.md +39 -0
- package/docs/ecosystem/utils/format-phone-number.md +43 -0
- package/docs/ecosystem/utils/get-browser-locale.md +35 -0
- package/docs/ecosystem/utils/get-country-flag-url.md +67 -0
- package/docs/ecosystem/utils/get-error-message.md +45 -0
- package/docs/ecosystem/utils/idle-timeout.md +96 -0
- package/docs/ecosystem/utils/index.md +57 -0
- package/docs/ecosystem/utils/is-client.md +38 -0
- package/docs/ecosystem/utils/is-equal.md +44 -0
- package/docs/ecosystem/utils/is-ios.md +43 -0
- package/docs/ecosystem/utils/is-server.md +37 -0
- package/docs/ecosystem/utils/is-standalone-mode.md +49 -0
- package/docs/ecosystem/utils/kebab-case.md +42 -0
- package/docs/ecosystem/utils/normalize-string.md +83 -0
- package/docs/ecosystem/utils/number.md +51 -0
- package/docs/ecosystem/utils/pascal-case.md +41 -0
- package/docs/ecosystem/utils/prevent-ios-input-zoom.md +72 -0
- package/docs/ecosystem/utils/script-loader.md +85 -0
- package/docs/ecosystem/utils/sleep.md +65 -0
- package/docs/ecosystem/utils/snake-case.md +42 -0
- package/docs/ecosystem/utils/swipe-handler.md +97 -0
- package/docs/ecosystem/utils/textarea-autogrow.md +47 -0
- package/docs/ecosystem/utils/throttle-id.md +54 -0
- package/docs/ecosystem/utils/throttle.md +63 -0
- package/docs/ecosystem/utils/truthy-filter.md +37 -0
- package/docs/ecosystem/utils/types/deep-key-of.md +54 -0
- package/docs/ecosystem/utils/types/deep-partial.md +48 -0
- package/docs/ecosystem/utils/types/deep-required.md +45 -0
- package/docs/ecosystem/utils/types/flatten-object-keys.md +50 -0
- package/docs/ecosystem/utils/types/generic-instance-type.md +48 -0
- package/docs/ecosystem/utils/types/infer-maybe-ref.md +41 -0
- package/docs/ecosystem/utils/upper-first.md +38 -0
- package/docs/ecosystem/utils/user-visibility.md +75 -0
- package/docs/guide/ai-agents.md +237 -0
- package/docs/guide/browser-support.md +88 -0
- package/docs/guide/getting-started.md +191 -0
- package/docs/guide/global-defaults.md +103 -0
- package/docs/guide/maz-ui-provider.md +231 -0
- package/docs/guide/migration-v5.md +871 -0
- package/docs/guide/resolvers.md +650 -0
- package/docs/guide/tailwind.md +483 -0
- package/docs/guide/vue.md +286 -0
- package/docs/manifest.json +1 -0
- package/docs/plugins/aos.md +312 -0
- package/docs/plugins/dialog.md +269 -0
- package/docs/plugins/toast.md +221 -0
- package/docs/plugins/wait.md +78 -0
- package/docs/reference/icons.md +46 -0
- package/docs/reference/tailwind-tokens.md +191 -0
- package/docs/rules.md +57 -0
- package/package.json +31 -4
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "camelCase"
|
|
3
|
+
description: "Convert a kebab-case string to camelCase by stripping dashes and uppercasing the following letter."
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/camel-case"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# camelCase
|
|
9
|
+
|
|
10
|
+
> Convert a kebab-case string to camelCase by stripping dashes and uppercasing the following letter.
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { camelCase } from '@maz-ui/utils/helpers/camelCase'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/camel-case
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { camelCase } from '@maz-ui/utils'
|
|
20
|
+
|
|
21
|
+
camelCase('my-component-name') // → 'myComponentName'
|
|
22
|
+
camelCase('hello-world') // → 'helloWorld'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
function camelCase(str: string): string
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Parameter | Type | Description |
|
|
32
|
+
| --------- | -------- | --------------------- |
|
|
33
|
+
| `str` | `string` | The string to convert |
|
|
34
|
+
|
|
35
|
+
## Notes
|
|
36
|
+
|
|
37
|
+
`camelCase` is intentionally minimal - it only handles `kebab-case` input. For more general normalization (snake_case, spaces, PascalCase), use [`normalizeString`](./normalize-string.md) with the `case: 'camelCase'` option.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "capitalize"
|
|
3
|
+
description: "The module capitalize is a function that adds a capital letter to a string"
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/capitalize"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# capitalize
|
|
9
|
+
|
|
10
|
+
> The module capitalize is a function that adds a capital letter to a string
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { capitalize } from '@maz-ui/utils/helpers/capitalize'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/capitalize
|
|
15
|
+
|
|
16
|
+
```vue
|
|
17
|
+
<script lang="ts" setup>
|
|
18
|
+
import { capitalize } from '@maz-ui/utils'
|
|
19
|
+
import { computed, ref } from 'vue'
|
|
20
|
+
|
|
21
|
+
const stringValue = ref('string value')
|
|
22
|
+
|
|
23
|
+
const stringFormatted = computed(() =>
|
|
24
|
+
capitalize(stringValue.value),
|
|
25
|
+
)
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<MazInput v-model="stringValue" />
|
|
30
|
+
|
|
31
|
+
<div
|
|
32
|
+
class="flex flex-center rounded-md gap-0.5 p-4 mt-16 bg-surface-300"
|
|
33
|
+
>
|
|
34
|
+
{{ stringFormatted }}
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
37
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "checkAvailability"
|
|
3
|
+
description: "Poll a getter until a value is available (or matches an expected value), then run a callback - with timeout and configurable retry interval."
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/check-availability"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# checkAvailability
|
|
9
|
+
|
|
10
|
+
> Poll a getter until a value is available (or matches an expected value), then run a callback - with timeout and configurable retry interval.
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { checkAvailability } from '@maz-ui/utils/helpers/checkAvailability'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/check-availability
|
|
15
|
+
|
|
16
|
+
Useful for waiting on a third-party SDK to attach itself to `window`, on a Vue ref to be populated after mount, or on any asynchronously-available value.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { checkAvailability } from '@maz-ui/utils'
|
|
22
|
+
|
|
23
|
+
checkAvailability(
|
|
24
|
+
() => window.Stripe,
|
|
25
|
+
(Stripe) => {
|
|
26
|
+
const stripe = Stripe('pk_...')
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## API
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
function checkAvailability<T>(
|
|
35
|
+
getRef: () => T | null | undefined,
|
|
36
|
+
callback: (value: NonNullable<T>) => void,
|
|
37
|
+
options?: {
|
|
38
|
+
maxAttempts?: number
|
|
39
|
+
interval?: number
|
|
40
|
+
expectedValue?: T
|
|
41
|
+
errorMessage?: string
|
|
42
|
+
onError?: (error: Error) => void
|
|
43
|
+
},
|
|
44
|
+
): void
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
| Option | Type | Default | Description |
|
|
48
|
+
| --------------- | ---------- | ------- | ---------------------------------------------------------------------- |
|
|
49
|
+
| `maxAttempts` | `number` | `20` | Number of polls before giving up |
|
|
50
|
+
| `interval` | `number` | `100` | Delay between polls, in milliseconds |
|
|
51
|
+
| `expectedValue` | `T` | - | When set, callback fires only when `getRef()` strictly equals this value |
|
|
52
|
+
| `errorMessage` | `string` | - | Custom error message when `maxAttempts` is exceeded |
|
|
53
|
+
| `onError` | `Function` | - | Called with the timeout `Error` instead of throwing |
|
|
54
|
+
|
|
55
|
+
With default options, the helper polls every 100 ms up to 20 times - a 2 second timeout in total.
|
|
56
|
+
|
|
57
|
+
## Examples
|
|
58
|
+
|
|
59
|
+
Wait for a global SDK with a custom timeout:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
checkAvailability(
|
|
63
|
+
() => window.gtag,
|
|
64
|
+
(gtag) => {
|
|
65
|
+
gtag('event', 'page_view')
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
maxAttempts: 50,
|
|
69
|
+
interval: 200,
|
|
70
|
+
onError: (err) => {
|
|
71
|
+
console.warn('gtag never loaded', err)
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Wait for a specific value (e.g. SDK becomes ready):
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
checkAvailability(
|
|
81
|
+
() => window.__SDK_STATE__,
|
|
82
|
+
() => boot(),
|
|
83
|
+
{ expectedValue: 'ready' },
|
|
84
|
+
)
|
|
85
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "cookie"
|
|
3
|
+
description: "Read, write and delete browser cookies with full attribute support - `path`, `domain`, `maxAge`, `expires`, `secure`, `sameSite`, `partitioned`."
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/cookie"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# cookie
|
|
9
|
+
|
|
10
|
+
> Read, write and delete browser cookies with full attribute support - `path`, `domain`, `maxAge`, `expires`, `secure`, `sameSite`, `partitioned`.
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { getCookie, setCookie, deleteCookie } from '@maz-ui/utils/helpers/cookie'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/cookie
|
|
15
|
+
|
|
16
|
+
The module exports three functions: `getCookie`, `setCookie`, `deleteCookie`. Reads work both on the client (via `document.cookie`) and on the server (when you pass the raw `Cookie` header).
|
|
17
|
+
|
|
18
|
+
## getCookie
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { getCookie } from '@maz-ui/utils'
|
|
22
|
+
|
|
23
|
+
const theme = getCookie('theme') // 'dark' | null
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
function getCookie(key: string, cookieHeader?: string): string | null
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| Parameter | Type | Description |
|
|
31
|
+
| -------------- | -------- | -------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `key` | `string` | Cookie name |
|
|
33
|
+
| `cookieHeader` | `string` | (Optional) Raw `Cookie` request header - pass during SSR (e.g. from `useSSRContext()` in Nuxt) |
|
|
34
|
+
|
|
35
|
+
Returns the URL-decoded value, or `null` when the cookie is absent.
|
|
36
|
+
|
|
37
|
+
## setCookie
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { setCookie } from '@maz-ui/utils'
|
|
41
|
+
|
|
42
|
+
setCookie('theme', 'dark')
|
|
43
|
+
|
|
44
|
+
setCookie('session', token, {
|
|
45
|
+
maxAge: 60 * 60, // 1 hour
|
|
46
|
+
secure: true,
|
|
47
|
+
sameSite: 'Strict',
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
function setCookie(key: string, value: string, options?: CookieOptions): void
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
No-op on the server.
|
|
56
|
+
|
|
57
|
+
### Options
|
|
58
|
+
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
| ------------- | --------- | ---------------- | --------------------------------------------------------------------------------- |
|
|
61
|
+
| `path` | `string` | `'/'` | Path attribute. Pass `null` to omit. |
|
|
62
|
+
| `domain` | `string` | - | Domain attribute. |
|
|
63
|
+
| `maxAge` | `number` | `31_536_000` (1y) | Lifetime in seconds. Pass `null` for a session cookie. |
|
|
64
|
+
| `expires` | `Date` | - | Explicit expiration date. Takes precedence over `maxAge`. |
|
|
65
|
+
| `secure` | `boolean` | - | Restrict to HTTPS. |
|
|
66
|
+
| `sameSite` | `'Lax' \| 'Strict' \| 'None'` | `'Lax'` | Same-site policy. Pass `null` to omit. |
|
|
67
|
+
| `partitioned` | `boolean` | - | Mark the cookie as partitioned (CHIPS). |
|
|
68
|
+
|
|
69
|
+
**Warning: `HttpOnly`**
|
|
70
|
+
|
|
71
|
+
`HttpOnly` cannot be set from `document.cookie` - browsers reject it. Use a server-set cookie for that.
|
|
72
|
+
|
|
73
|
+
## deleteCookie
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { deleteCookie } from '@maz-ui/utils'
|
|
77
|
+
|
|
78
|
+
deleteCookie('session')
|
|
79
|
+
deleteCookie('analytics-id', { domain: '.example.com' })
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
function deleteCookie(key: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
For the deletion to take effect, `path` and `domain` must match the values used when the cookie was set.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "country-code-to-unicode-flag"
|
|
3
|
+
description: "Convert country code in unicode flag"
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/country-code-to-unicode-flag"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# country-code-to-unicode-flag
|
|
9
|
+
|
|
10
|
+
> Convert country code in unicode flag
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { countryCodeToUnicodeFlag } from '@maz-ui/utils/helpers/countryCodeToUnicodeFlag'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/country-code-to-unicode-flag
|
|
15
|
+
|
|
16
|
+
**Warning:**
|
|
17
|
+
|
|
18
|
+
This feature does not work with Windows but you can use this polyfill: [https://www.npmjs.com/package/country-flag-emoji-polyfill](https://www.npmjs.com/package/country-flag-emoji-polyfill)
|
|
19
|
+
|
|
20
|
+
Use can also use [get-country-flag-url](./get-country-flag-url.md) instead.
|
|
21
|
+
|
|
22
|
+
## Basic usage
|
|
23
|
+
|
|
24
|
+
```vue
|
|
25
|
+
<template>
|
|
26
|
+
<span style="font-size: 2rem;">
|
|
27
|
+
{{ unicodeFlag }}
|
|
28
|
+
</span>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script lang="ts" setup >
|
|
32
|
+
import { countryCodeToUnicodeFlag } from '@maz-ui/utils'
|
|
33
|
+
|
|
34
|
+
const unicodeFlag = countryCodeToUnicodeFlag('FR')
|
|
35
|
+
</script>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+
**Details: Show full code**
|
|
41
|
+
|
|
42
|
+
```vue
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<div class="gap-2 flex flex-wrap items-center">
|
|
46
|
+
<span class="text-xs">{{ flag }}</span>
|
|
47
|
+
<span class="text-sm">{{ flag }}</span>
|
|
48
|
+
<span class="text-base">{{ flag }}</span>
|
|
49
|
+
<span class="text-lg">{{ flag }}</span>
|
|
50
|
+
<span class="text-xl">{{ flag }}</span>
|
|
51
|
+
<span class="text-2xl">{{ flag }}</span>
|
|
52
|
+
<span class="text-3xl">{{ flag }}</span>
|
|
53
|
+
<span class="text-4xl">{{ flag }}</span>
|
|
54
|
+
<span class="text-5xl">{{ flag }}</span>
|
|
55
|
+
<span class="text-6xl">{{ flag }}</span>
|
|
56
|
+
<span class="text-7xl">{{ flag }}</span>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<MazSelect
|
|
60
|
+
v-model="countryCode"
|
|
61
|
+
:options="countryOptions"
|
|
62
|
+
label="Select country"
|
|
63
|
+
search
|
|
64
|
+
search-placeholder="Search country"
|
|
65
|
+
@selected-option="(option) => console.log('option', option)"
|
|
66
|
+
>
|
|
67
|
+
<template #default="{ option, isSelected }">
|
|
68
|
+
<div
|
|
69
|
+
class="flex items-center gap-3"
|
|
70
|
+
>
|
|
71
|
+
<span class="text-lg">
|
|
72
|
+
{{ option.unicodeFlag }}
|
|
73
|
+
</span>
|
|
74
|
+
<MazBadge
|
|
75
|
+
pastel
|
|
76
|
+
size="0.7rem"
|
|
77
|
+
class="w-9"
|
|
78
|
+
:class="{ 'text-muted': !isSelected }"
|
|
79
|
+
>
|
|
80
|
+
{{ option.value }}
|
|
81
|
+
</MazBadge>
|
|
82
|
+
<span :class="{ 'font-semibold': isSelected }">
|
|
83
|
+
{{ option.label }}
|
|
84
|
+
</span>
|
|
85
|
+
</div>
|
|
86
|
+
</template>
|
|
87
|
+
</MazSelect>
|
|
88
|
+
</template>
|
|
89
|
+
|
|
90
|
+
<script lang="ts" setup>
|
|
91
|
+
import { computed, ref, onMounted } from 'vue'
|
|
92
|
+
import { countryCodeToUnicodeFlag } from '@maz-ui/utils'
|
|
93
|
+
import { getCountries } from 'libphonenumber-js'
|
|
94
|
+
|
|
95
|
+
const countryCode = ref('FR')
|
|
96
|
+
const flag = computed(() => countryCodeToUnicodeFlag(countryCode.value))
|
|
97
|
+
|
|
98
|
+
const countryOptions = ref(getCountriesList())
|
|
99
|
+
|
|
100
|
+
onMounted(() => {
|
|
101
|
+
const listOfCountries = getCountriesList(window.navigator.language)
|
|
102
|
+
if (listOfCountries.length > 1) {
|
|
103
|
+
countryOptions.value = listOfCountries
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
function getCountriesList(
|
|
108
|
+
locale?: string,
|
|
109
|
+
) {
|
|
110
|
+
const countriesList = []
|
|
111
|
+
const isoList = getCountries()
|
|
112
|
+
|
|
113
|
+
for (const iso2 of isoList) {
|
|
114
|
+
const name = new Intl.DisplayNames([locale ?? 'en-US'], { type: 'region' }).of(iso2)
|
|
115
|
+
|
|
116
|
+
if (name) {
|
|
117
|
+
countriesList.push({
|
|
118
|
+
value: iso2,
|
|
119
|
+
label: name,
|
|
120
|
+
unicodeFlag: countryCodeToUnicodeFlag(iso2)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return countriesList
|
|
126
|
+
}
|
|
127
|
+
</script>
|
|
128
|
+
```
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "formatCurrency"
|
|
3
|
+
description: "The module formatCurrency is a function that formats numbers to currency with the native api [Intl.NumberFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) from browsers and Node.js"
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/currency"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# formatCurrency
|
|
9
|
+
|
|
10
|
+
> The module formatCurrency is a function that formats numbers to currency with the native api [Intl.NumberFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) from browsers and Node.js
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { formatCurrency } from '@maz-ui/utils/helpers/formatCurrency'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/currency
|
|
15
|
+
|
|
16
|
+
**Tip:**
|
|
17
|
+
|
|
18
|
+
This module uses the native api [Intl.NumberFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) from browsers
|
|
19
|
+
|
|
20
|
+
Enter only numbers
|
|
21
|
+
|
|
22
|
+
```vue
|
|
23
|
+
<script lang="ts" setup>
|
|
24
|
+
import { formatCurrency } from '@maz-ui/utils'
|
|
25
|
+
import { computed, ref } from 'vue'
|
|
26
|
+
|
|
27
|
+
const numberValue = ref(69)
|
|
28
|
+
|
|
29
|
+
const priceFormatted = computed(() =>
|
|
30
|
+
formatCurrency(numberValue.value, 'fr-FR', { currency: 'EUR' }),
|
|
31
|
+
)
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<MazInput v-model="numberValue" type="number" />
|
|
36
|
+
|
|
37
|
+
<div
|
|
38
|
+
style="padding: 16px; margin-top: 16px; background-color: var(--maz-surface-300);"
|
|
39
|
+
>
|
|
40
|
+
{{ priceFormatted }}
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
> All options from [Intl.NumberFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) are availables
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
export interface FilterCurrencyOptions extends Intl.NumberFormatOptions {
|
|
51
|
+
round?: boolean
|
|
52
|
+
}
|
|
53
|
+
```
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "formatDate"
|
|
3
|
+
description: "The module formatDate is a function that formats dates with the native api [Intl.DateTimeFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) from browsers and Node.js"
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/date"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# formatDate
|
|
9
|
+
|
|
10
|
+
> The module formatDate is a function that formats dates with the native api [Intl.DateTimeFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) from browsers and Node.js
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { formatDate } from '@maz-ui/utils/helpers/formatDate'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/date
|
|
15
|
+
|
|
16
|
+
> This module use the native api [Intl.DateTimeFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) from browsers
|
|
17
|
+
|
|
18
|
+
```vue
|
|
19
|
+
<script lang="ts" setup>
|
|
20
|
+
import { formatDate } from '@maz-ui/utils'
|
|
21
|
+
import { computed, ref } from 'vue'
|
|
22
|
+
|
|
23
|
+
const dateValue = ref('2022-02-01')
|
|
24
|
+
|
|
25
|
+
const dateFormatted = computed(() =>
|
|
26
|
+
dateValue.value ? formatDate(dateValue.value, 'en-US') : undefined,
|
|
27
|
+
)
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<MazInput v-model="dateValue" type="date" />
|
|
32
|
+
|
|
33
|
+
<div
|
|
34
|
+
style="padding: 16px; margin-top: 16px; background-color: var(--maz-surface-300);"
|
|
35
|
+
>
|
|
36
|
+
{{ dateFormatted }}
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Options
|
|
42
|
+
|
|
43
|
+
> All options from [Intl.DateTimeFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) are available
|
|
44
|
+
|
|
45
|
+
## Default options
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const DEFAULT_OPTIONS: Intl.DateTimeFormatOptions = {
|
|
49
|
+
month: 'short',
|
|
50
|
+
day: 'numeric',
|
|
51
|
+
year: 'numeric',
|
|
52
|
+
}
|
|
53
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "debounceCallback"
|
|
3
|
+
description: "Module-scoped one-shot debounce - schedule a callback that gets reset on each new call."
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/debounce-callback"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# debounceCallback
|
|
9
|
+
|
|
10
|
+
> Module-scoped one-shot debounce - schedule a callback that gets reset on each new call.
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { debounceCallback } from '@maz-ui/utils/helpers/debounceCallback'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/debounce-callback
|
|
15
|
+
|
|
16
|
+
Unlike [`debounce`](./debounce.md), which builds a debounced wrapper around a function, `debounceCallback` is a procedural helper: each call schedules a callback after `delay` ms, cancelling any previous pending callback.
|
|
17
|
+
|
|
18
|
+
**Warning: Shared module state**
|
|
19
|
+
|
|
20
|
+
`debounceCallback` uses a single module-level timer. All consumers of this function share the same timer slot, so calling it from two unrelated places will cancel each other. Use [`debounceId`](./debounce-id.md) for isolated debounces.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { debounceCallback } from '@maz-ui/utils'
|
|
26
|
+
|
|
27
|
+
debounceCallback(() => {
|
|
28
|
+
console.log('runs only if no other call happens in the next 300 ms')
|
|
29
|
+
}, 300)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
function debounceCallback(
|
|
36
|
+
callback: (...args: unknown[]) => unknown,
|
|
37
|
+
delay: number,
|
|
38
|
+
): void
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
| Parameter | Type | Description |
|
|
42
|
+
| ---------- | ---------- | ------------------------------------------ |
|
|
43
|
+
| `callback` | `Function` | Function to run after the quiet window |
|
|
44
|
+
| `delay` | `number` | Quiet window before firing, in milliseconds |
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "debounceId"
|
|
3
|
+
description: "Debounce an async function with isolated state per identifier - only the last call resolves, others are cancelled."
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/debounce-id"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# debounceId
|
|
9
|
+
|
|
10
|
+
> Debounce an async function with isolated state per identifier - only the last call resolves, others are cancelled.
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { debounceId } from '@maz-ui/utils/helpers/debounceId'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/debounce-id
|
|
15
|
+
|
|
16
|
+
`debounceId` is the right tool when:
|
|
17
|
+
|
|
18
|
+
- You need to debounce **async** work and `await` the result.
|
|
19
|
+
- You want **per-key isolation** - debounces for `'search'` shouldn't interfere with debounces for `'autosave'`.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { debounceId } from '@maz-ui/utils'
|
|
25
|
+
|
|
26
|
+
const searchUsers = debounceId(
|
|
27
|
+
'user-search',
|
|
28
|
+
async (query: string) => {
|
|
29
|
+
const res = await fetch(`/api/users?q=${query}`)
|
|
30
|
+
return res.json()
|
|
31
|
+
},
|
|
32
|
+
300,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const users = await searchUsers('alice')
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
function debounceId<T, Args extends unknown[]>(
|
|
42
|
+
identifier: string,
|
|
43
|
+
func: (...args: Args) => T | Promise<T>,
|
|
44
|
+
delay: number,
|
|
45
|
+
): (...args: Args) => Promise<T>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| Parameter | Type | Description |
|
|
49
|
+
| ------------ | --------------- | ------------------------------------------------------------ |
|
|
50
|
+
| `identifier` | `string` | Unique key - calls with the same key share a debounce timer |
|
|
51
|
+
| `func` | `Function` | The async (or sync) function to debounce |
|
|
52
|
+
| `delay` | `number` | Quiet window before the call resolves, in ms |
|
|
53
|
+
|
|
54
|
+
Returns a function that always returns a `Promise<T>`. Earlier pending promises are cancelled - only the last invocation resolves.
|
|
55
|
+
|
|
56
|
+
## Examples
|
|
57
|
+
|
|
58
|
+
Autosave a form, keyed by document ID, so concurrent edits to different documents don't share state:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { debounceId } from '@maz-ui/utils'
|
|
62
|
+
|
|
63
|
+
async function saveDocument(id: string, payload: unknown) {
|
|
64
|
+
const save = debounceId(
|
|
65
|
+
`doc-${id}`,
|
|
66
|
+
(body: unknown) => fetch(`/docs/${id}`, { method: 'PUT', body: JSON.stringify(body) }),
|
|
67
|
+
500,
|
|
68
|
+
)
|
|
69
|
+
return save(payload)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Related
|
|
74
|
+
|
|
75
|
+
- [`throttleId`](./throttle-id.md) - same shape, but throttles instead of debounces.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "debounce"
|
|
3
|
+
description: "Wrap a function so it only runs after a quiet period - every new call resets the timer."
|
|
4
|
+
package: "@maz-ui/utils"
|
|
5
|
+
url: "https://maz-ui.com/ecosystem/utils/debounce"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# debounce
|
|
9
|
+
|
|
10
|
+
> Wrap a function so it only runs after a quiet period - every new call resets the timer.
|
|
11
|
+
|
|
12
|
+
- Package: `@maz-ui/utils`
|
|
13
|
+
- Import: `import { debounce } from '@maz-ui/utils/helpers/debounce'`
|
|
14
|
+
- Web: https://maz-ui.com/ecosystem/utils/debounce
|
|
15
|
+
|
|
16
|
+
Useful for input handlers, resize listeners, search-as-you-type and any callback that should not fire on every event.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { debounce } from '@maz-ui/utils'
|
|
22
|
+
|
|
23
|
+
const onSearch = debounce((query: string) => {
|
|
24
|
+
console.log('searching for', query)
|
|
25
|
+
}, 300)
|
|
26
|
+
|
|
27
|
+
onSearch('h')
|
|
28
|
+
onSearch('he')
|
|
29
|
+
onSearch('hel')
|
|
30
|
+
// only the last call (with "hel") runs, 300 ms after the third call
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
function debounce<F extends (...args: any[]) => any>(
|
|
37
|
+
fn: F,
|
|
38
|
+
delay: number,
|
|
39
|
+
): (...args: Parameters<F>) => void
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Parameter | Type | Description |
|
|
43
|
+
| --------- | ---------- | --------------------------------------------- |
|
|
44
|
+
| `fn` | `Function` | The function to debounce |
|
|
45
|
+
| `delay` | `number` | Quiet window in milliseconds before `fn` runs |
|
|
46
|
+
|
|
47
|
+
The returned function shares no state with other debounced wrappers - each call to `debounce()` creates a fresh timer.
|
|
48
|
+
|
|
49
|
+
## Examples
|
|
50
|
+
|
|
51
|
+
Debounce a Vue input handler:
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<script setup lang="ts">
|
|
55
|
+
import { debounce } from '@maz-ui/utils'
|
|
56
|
+
|
|
57
|
+
const onInput = debounce((event: Event) => {
|
|
58
|
+
console.log((event.target as HTMLInputElement).value)
|
|
59
|
+
}, 250)
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<input @input="onInput">
|
|
64
|
+
</template>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Related
|
|
68
|
+
|
|
69
|
+
- [`debounceId`](./debounce-id.md) - debounce an async function, keyed by an identifier, returning a promise.
|
|
70
|
+
- [`debounceCallback`](./debounce-callback.md) - module-scoped one-shot debounce.
|
|
71
|
+
- [`throttle`](./throttle.md) - rate-limits instead of waiting for silence.
|