@scripso-homepad/ui 0.4.39 → 0.4.41
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/index.cjs +52 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +47 -7
- package/dist/index.js.map +1 -1
- package/dist/web/index.cjs +42 -14
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +1 -1
- package/dist/web/index.d.ts +1 -1
- package/dist/web/index.js +42 -14
- package/dist/web/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/PhoneInput.stories.tsx +1 -2
- package/src/components/PhoneInput.tsx +24 -8
- package/src/index.ts +9 -0
- package/src/utils/phoneFormat.test.ts +34 -0
- package/src/utils/phoneFormat.ts +57 -0
- package/src/web/components/Drawer.tsx +11 -3
- package/src/web/components/table/TablePrimitives.tsx +26 -5
- package/src/web/layout/DashboardLayout.tsx +3 -3
- package/src/web/layout/Sidebar.tsx +2 -2
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from "react-native";
|
|
14
14
|
import { CountryCodeSelector } from "./CountryCodeSelector";
|
|
15
15
|
import { Label } from "./Label";
|
|
16
|
+
import { defaultCountry } from "../data/countries";
|
|
16
17
|
import {
|
|
17
18
|
getInputFieldStyles,
|
|
18
19
|
inputFieldMetrics,
|
|
@@ -22,6 +23,12 @@ import {
|
|
|
22
23
|
resolveInputVisualState,
|
|
23
24
|
} from "../theme/input";
|
|
24
25
|
import { colors, radii, spacing } from "../theme/tokens";
|
|
26
|
+
import {
|
|
27
|
+
ARMENIAN_PHONE_PLACEHOLDER,
|
|
28
|
+
DEFAULT_PHONE_COUNTRY_CODE,
|
|
29
|
+
formatNationalPhoneDisplay,
|
|
30
|
+
sanitizeNationalPhoneDigits,
|
|
31
|
+
} from "../utils/phoneFormat";
|
|
25
32
|
import { useApplyWebClassName } from "../utils/useApplyWebClassName";
|
|
26
33
|
|
|
27
34
|
/** Keep country trigger outer box equal to the phone field (transparent focus ring). */
|
|
@@ -52,14 +59,9 @@ export interface PhoneInputProps extends Omit<TextInputProps, "style"> {
|
|
|
52
59
|
hintClassName?: string;
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
/** National phone field: digits only (blocks pasted letters/symbols). */
|
|
56
|
-
function sanitizePhoneDigits(value: string): string {
|
|
57
|
-
return value.replace(/\D/g, "");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
62
|
export function PhoneInput({
|
|
61
63
|
label,
|
|
62
|
-
countryCode,
|
|
64
|
+
countryCode = defaultCountry.code,
|
|
63
65
|
onCountryCodeChange,
|
|
64
66
|
error,
|
|
65
67
|
hint,
|
|
@@ -76,6 +78,8 @@ export function PhoneInput({
|
|
|
76
78
|
onFocus,
|
|
77
79
|
onBlur,
|
|
78
80
|
onChangeText,
|
|
81
|
+
value,
|
|
82
|
+
placeholder,
|
|
79
83
|
...props
|
|
80
84
|
}: PhoneInputProps) {
|
|
81
85
|
const wrapperRef = useRef<ComponentRef<typeof View>>(null);
|
|
@@ -94,6 +98,16 @@ export function PhoneInput({
|
|
|
94
98
|
disabled: isDisabled,
|
|
95
99
|
});
|
|
96
100
|
const phoneFieldStyles = getInputFieldStyles(phoneVisualState);
|
|
101
|
+
const resolvedCountryCode = countryCode || DEFAULT_PHONE_COUNTRY_CODE;
|
|
102
|
+
const displayValue =
|
|
103
|
+
typeof value === "string" || typeof value === "number"
|
|
104
|
+
? formatNationalPhoneDisplay(String(value), resolvedCountryCode)
|
|
105
|
+
: value;
|
|
106
|
+
const resolvedPlaceholder =
|
|
107
|
+
placeholder ??
|
|
108
|
+
(resolvedCountryCode === DEFAULT_PHONE_COUNTRY_CODE
|
|
109
|
+
? ARMENIAN_PHONE_PLACEHOLDER
|
|
110
|
+
: undefined);
|
|
97
111
|
|
|
98
112
|
function handleFocus(event: NativeSyntheticEvent<TextInputFocusEventData>) {
|
|
99
113
|
setFocused(true);
|
|
@@ -105,8 +119,8 @@ export function PhoneInput({
|
|
|
105
119
|
onBlur?.(event);
|
|
106
120
|
}
|
|
107
121
|
|
|
108
|
-
function handleChangeText(
|
|
109
|
-
onChangeText?.(
|
|
122
|
+
function handleChangeText(nextValue: string) {
|
|
123
|
+
onChangeText?.(sanitizeNationalPhoneDigits(nextValue, resolvedCountryCode));
|
|
110
124
|
}
|
|
111
125
|
|
|
112
126
|
const helperMessage = error ?? hint;
|
|
@@ -158,6 +172,8 @@ export function PhoneInput({
|
|
|
158
172
|
onBlur={handleBlur}
|
|
159
173
|
accessibilityState={{ disabled: isDisabled }}
|
|
160
174
|
{...props}
|
|
175
|
+
value={displayValue}
|
|
176
|
+
placeholder={resolvedPlaceholder}
|
|
161
177
|
onChangeText={handleChangeText}
|
|
162
178
|
/>
|
|
163
179
|
</View>
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,15 @@ export type {
|
|
|
19
19
|
export { PhoneInput } from "./components/PhoneInput";
|
|
20
20
|
export type { PhoneInputProps } from "./components/PhoneInput";
|
|
21
21
|
|
|
22
|
+
export {
|
|
23
|
+
ARMENIAN_PHONE_PLACEHOLDER,
|
|
24
|
+
DEFAULT_PHONE_COUNTRY_CODE,
|
|
25
|
+
formatArmenianNationalNumber,
|
|
26
|
+
formatNationalPhoneDisplay,
|
|
27
|
+
getPhoneDigits,
|
|
28
|
+
sanitizeNationalPhoneDigits,
|
|
29
|
+
} from "./utils/phoneFormat";
|
|
30
|
+
|
|
22
31
|
export { CountryCodeSelector } from "./components/CountryCodeSelector";
|
|
23
32
|
export type { CountryCodeSelectorProps } from "./components/CountryCodeSelector";
|
|
24
33
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ARMENIAN_PHONE_PLACEHOLDER,
|
|
6
|
+
formatArmenianNationalNumber,
|
|
7
|
+
formatNationalPhoneDisplay,
|
|
8
|
+
sanitizeNationalPhoneDigits,
|
|
9
|
+
} from './phoneFormat';
|
|
10
|
+
|
|
11
|
+
describe('phoneFormat', () => {
|
|
12
|
+
it('formats Armenia national numbers while typing', () => {
|
|
13
|
+
assert.equal(formatArmenianNationalNumber('9'), '(9');
|
|
14
|
+
assert.equal(formatArmenianNationalNumber('91'), '(91');
|
|
15
|
+
assert.equal(formatArmenianNationalNumber('914'), '(91) 4');
|
|
16
|
+
assert.equal(formatArmenianNationalNumber('9144'), '(91) 44');
|
|
17
|
+
assert.equal(formatArmenianNationalNumber('914455'), '(91) 44-55');
|
|
18
|
+
assert.equal(formatArmenianNationalNumber('91445566'), '(91) 44-55-66');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('caps Armenia national numbers at 8 digits', () => {
|
|
22
|
+
assert.equal(sanitizeNationalPhoneDigits('9144556699', 'AM'), '91445566');
|
|
23
|
+
assert.equal(formatNationalPhoneDisplay('9144556699', 'AM'), '(91) 44-55-66');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('leaves non-Armenia numbers as digits', () => {
|
|
27
|
+
assert.equal(formatNationalPhoneDisplay('555123456', 'GE'), '555123456');
|
|
28
|
+
assert.equal(sanitizeNationalPhoneDigits('(555) 123-456', 'GE'), '555123456');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('exposes the Armenia placeholder mask', () => {
|
|
32
|
+
assert.equal(ARMENIAN_PHONE_PLACEHOLDER, '(00) 00-00-00');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { defaultCountry } from "../data/countries";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_PHONE_COUNTRY_CODE = defaultCountry.code;
|
|
4
|
+
const AM_NATIONAL_MAX_DIGITS = 8;
|
|
5
|
+
const MAX_NATIONAL_DIGITS = 15;
|
|
6
|
+
|
|
7
|
+
export function getPhoneDigits(value: string): string {
|
|
8
|
+
return value.replace(/\D/g, "");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Armenia mobile display while typing: (91) 44-55-66 */
|
|
12
|
+
export function formatArmenianNationalNumber(digits: string): string {
|
|
13
|
+
const national = getPhoneDigits(digits).slice(0, AM_NATIONAL_MAX_DIGITS);
|
|
14
|
+
|
|
15
|
+
if (national.length === 0) {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (national.length <= 2) {
|
|
20
|
+
return `(${national}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const head = national.slice(0, 2);
|
|
24
|
+
const rest = national.slice(2);
|
|
25
|
+
const groups = rest.match(/.{1,2}/g) ?? [];
|
|
26
|
+
|
|
27
|
+
return `(${head}) ${groups.join("-")}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function formatNationalPhoneDisplay(
|
|
31
|
+
digits: string,
|
|
32
|
+
countryCode: string = DEFAULT_PHONE_COUNTRY_CODE,
|
|
33
|
+
): string {
|
|
34
|
+
const national = getPhoneDigits(digits).slice(0, MAX_NATIONAL_DIGITS);
|
|
35
|
+
|
|
36
|
+
if (countryCode === DEFAULT_PHONE_COUNTRY_CODE) {
|
|
37
|
+
return formatArmenianNationalNumber(national);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return national;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function sanitizeNationalPhoneDigits(
|
|
44
|
+
value: string,
|
|
45
|
+
countryCode: string = DEFAULT_PHONE_COUNTRY_CODE,
|
|
46
|
+
): string {
|
|
47
|
+
const digits = getPhoneDigits(value);
|
|
48
|
+
|
|
49
|
+
if (countryCode === DEFAULT_PHONE_COUNTRY_CODE) {
|
|
50
|
+
return digits.slice(0, AM_NATIONAL_MAX_DIGITS);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return digits.slice(0, MAX_NATIONAL_DIGITS);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Placeholder mask shown for Armenia national numbers. */
|
|
57
|
+
export const ARMENIAN_PHONE_PLACEHOLDER = "(00) 00-00-00";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { X } from 'lucide-react';
|
|
2
2
|
import { useEffect, useState, type ReactNode } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
3
4
|
|
|
4
5
|
import { useBackdropDismiss } from '../hooks/useBackdropDismiss';
|
|
5
6
|
import { cn } from '../utils/cn';
|
|
@@ -10,6 +11,7 @@ const DRAWER_TRANSITION_MS = 300;
|
|
|
10
11
|
|
|
11
12
|
let bodyScrollLockCount = 0;
|
|
12
13
|
let previousBodyOverflow = '';
|
|
14
|
+
let previousHtmlOverflow = '';
|
|
13
15
|
|
|
14
16
|
function lockBodyScroll() {
|
|
15
17
|
if (typeof document === 'undefined') {
|
|
@@ -18,7 +20,9 @@ function lockBodyScroll() {
|
|
|
18
20
|
|
|
19
21
|
if (bodyScrollLockCount === 0) {
|
|
20
22
|
previousBodyOverflow = document.body.style.overflow;
|
|
23
|
+
previousHtmlOverflow = document.documentElement.style.overflow;
|
|
21
24
|
document.body.style.overflow = 'hidden';
|
|
25
|
+
document.documentElement.style.overflow = 'hidden';
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
bodyScrollLockCount += 1;
|
|
@@ -33,7 +37,9 @@ function unlockBodyScroll() {
|
|
|
33
37
|
|
|
34
38
|
if (bodyScrollLockCount === 0) {
|
|
35
39
|
document.body.style.overflow = previousBodyOverflow;
|
|
40
|
+
document.documentElement.style.overflow = previousHtmlOverflow;
|
|
36
41
|
previousBodyOverflow = '';
|
|
42
|
+
previousHtmlOverflow = '';
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
|
|
@@ -141,9 +147,9 @@ export function Drawer({
|
|
|
141
147
|
return null;
|
|
142
148
|
}
|
|
143
149
|
|
|
144
|
-
|
|
150
|
+
const drawer = (
|
|
145
151
|
<div
|
|
146
|
-
className="fixed inset-0 z-50 flex justify-end p-2 max-md:p-0"
|
|
152
|
+
className="fixed inset-0 z-50 flex justify-end overscroll-none p-2 max-md:p-0"
|
|
147
153
|
role="presentation"
|
|
148
154
|
>
|
|
149
155
|
<button
|
|
@@ -163,7 +169,7 @@ export function Drawer({
|
|
|
163
169
|
aria-labelledby="homepad-drawer-title"
|
|
164
170
|
{...(subtitle ? { 'aria-describedby': 'homepad-drawer-subtitle' } : {})}
|
|
165
171
|
className={cn(
|
|
166
|
-
'relative z-10 flex h-
|
|
172
|
+
'relative z-10 flex h-full max-h-full min-h-0 cursor-auto flex-col overflow-hidden rounded-[16px] bg-white shadow-2xl transition-transform duration-300 ease-in-out max-md:rounded-none',
|
|
167
173
|
// Keep GPU transform only while animating — settled translate-x-0 blurs text.
|
|
168
174
|
!isTransformSettled && 'will-change-transform',
|
|
169
175
|
isAnimatedIn
|
|
@@ -229,4 +235,6 @@ export function Drawer({
|
|
|
229
235
|
</aside>
|
|
230
236
|
</div>
|
|
231
237
|
);
|
|
238
|
+
|
|
239
|
+
return typeof document !== 'undefined' ? createPortal(drawer, document.body) : drawer;
|
|
232
240
|
}
|
|
@@ -111,22 +111,22 @@ export function TableHead({
|
|
|
111
111
|
sortDirection = null,
|
|
112
112
|
onSort,
|
|
113
113
|
children,
|
|
114
|
+
onClick,
|
|
115
|
+
onKeyDown,
|
|
114
116
|
...props
|
|
115
117
|
}: TableHeadProps) {
|
|
116
118
|
const isSortable = sortable && onSort != null;
|
|
117
119
|
|
|
118
120
|
const content = isSortable ? (
|
|
119
|
-
<
|
|
120
|
-
type="button"
|
|
121
|
-
onClick={onSort}
|
|
121
|
+
<span
|
|
122
122
|
className={cn(
|
|
123
|
-
'inline-flex w-full
|
|
123
|
+
'inline-flex w-full items-center gap-2.5 font-[inherit] text-[length:inherit] leading-[inherit] tracking-[inherit] text-inherit',
|
|
124
124
|
tableHeadSortButtonAlignClasses[align],
|
|
125
125
|
)}
|
|
126
126
|
>
|
|
127
127
|
<span>{children}</span>
|
|
128
128
|
<TableSortIcon direction={sortDirection} />
|
|
129
|
-
</
|
|
129
|
+
</span>
|
|
130
130
|
) : (
|
|
131
131
|
children
|
|
132
132
|
);
|
|
@@ -138,10 +138,31 @@ export function TableHead({
|
|
|
138
138
|
tableHeadPaddingClassName,
|
|
139
139
|
tableHeaderClassName,
|
|
140
140
|
!isSortable && tableAlignClasses[align],
|
|
141
|
+
isSortable && 'cursor-pointer select-none hover:text-storm-gray-500',
|
|
141
142
|
className,
|
|
142
143
|
)}
|
|
143
144
|
aria-sort={resolveAriaSort(sortDirection, isSortable)}
|
|
145
|
+
tabIndex={isSortable ? 0 : undefined}
|
|
144
146
|
{...props}
|
|
147
|
+
onClick={(event) => {
|
|
148
|
+
onClick?.(event);
|
|
149
|
+
if (event.defaultPrevented || !isSortable) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
onSort();
|
|
154
|
+
}}
|
|
155
|
+
onKeyDown={(event) => {
|
|
156
|
+
onKeyDown?.(event);
|
|
157
|
+
if (event.defaultPrevented || !isSortable) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
onSort();
|
|
164
|
+
}
|
|
165
|
+
}}
|
|
145
166
|
>
|
|
146
167
|
{content}
|
|
147
168
|
</th>
|
|
@@ -27,11 +27,11 @@ export function DashboardLayout({
|
|
|
27
27
|
mainClassName,
|
|
28
28
|
}: DashboardLayoutProps) {
|
|
29
29
|
return (
|
|
30
|
-
<div className={cn('flex h-
|
|
31
|
-
<div className="max-md:contents md:h-
|
|
30
|
+
<div className={cn('flex h-dvh min-w-0 overflow-hidden flex-row bg-storm-gray-0', className)}>
|
|
31
|
+
<div className="max-md:contents md:h-dvh md:shrink-0">
|
|
32
32
|
<Sidebar {...sidebar} />
|
|
33
33
|
</div>
|
|
34
|
-
<div className="flex h-
|
|
34
|
+
<div className="flex h-dvh min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
|
35
35
|
<SidebarMobileHeader {...mobileHeader} />
|
|
36
36
|
<AppHeader {...header} />
|
|
37
37
|
<main className={mainClassName ?? 'min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto p-4 xl:p-6'}>{children}</main>
|
|
@@ -173,12 +173,12 @@ export function Sidebar({
|
|
|
173
173
|
/>
|
|
174
174
|
|
|
175
175
|
{showCollapsedRail && mobileOpen ? (
|
|
176
|
-
<div className="h-
|
|
176
|
+
<div className="h-dvh w-[76px] shrink-0" aria-hidden />
|
|
177
177
|
) : null}
|
|
178
178
|
|
|
179
179
|
<aside
|
|
180
180
|
className={cn(
|
|
181
|
-
'fixed inset-y-0 left-0 z-50 flex h-
|
|
181
|
+
'fixed inset-y-0 left-0 z-50 flex h-dvh w-[min(300px,85vw)] flex-col gap-8 overflow-hidden bg-navy p-4 shadow-xl',
|
|
182
182
|
'transition-[transform,width,padding,gap] duration-300 ease-in-out will-change-[transform,width]',
|
|
183
183
|
mobileOpen ? 'translate-x-0' : '-translate-x-full pointer-events-none',
|
|
184
184
|
'md:relative md:z-auto md:w-[76px] md:translate-x-0 md:pointer-events-auto md:shadow-none md:items-center md:gap-2 md:px-3 md:py-4',
|