@pk-design/react-tailwind 1.13.1 → 1.14.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.
@@ -147,27 +147,36 @@ const THEMED_BTN_CLASS = {
147
147
  plain: 'text-[var(--ui-danger-text)] hover:bg-current/10 active:bg-current/15 focus-visible:outline-[var(--ui-danger-ring)]',
148
148
  },
149
149
  secondary: {
150
- default: 'text-gray-700 bg-white border border-[var(--ui-border)] hover:bg-gray-100 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-700 focus-visible:outline-[var(--ui-focus-ring)]',
151
- outlined: 'text-gray-700 hover:text-white border border-[var(--ui-border)] hover:bg-gray-700 dark:text-gray-200 dark:hover:text-white dark:hover:bg-gray-600 focus-visible:outline-[var(--ui-focus-ring)]',
150
+ default: 'text-gray-800 bg-gray-200 hover:bg-gray-300 active:bg-gray-300 dark:text-white dark:bg-gray-700 dark:hover:bg-gray-600 dark:active:bg-gray-600 focus-visible:outline-[var(--ui-focus-ring)]',
151
+ outlined: 'text-gray-800 bg-white border border-gray-300 shadow-xs hover:bg-gray-100 active:bg-gray-200 dark:text-gray-100 dark:bg-transparent dark:border-gray-600 dark:shadow-none dark:hover:bg-white/10 dark:active:bg-white/15 focus-visible:outline-[var(--ui-focus-ring)]',
152
152
  plain: 'text-gray-700 hover:bg-current/10 active:bg-current/15 dark:text-gray-200 focus-visible:outline-[var(--ui-focus-ring)]',
153
153
  },
154
154
  success: {
155
- default: 'text-white bg-emerald-600 hover:bg-emerald-700 focus-visible:outline-emerald-500',
156
- outlined: 'text-emerald-700 hover:text-white border border-emerald-600 hover:bg-emerald-600 dark:text-emerald-400 dark:border-emerald-500 focus-visible:outline-emerald-500',
155
+ default: 'text-white bg-emerald-700 hover:bg-emerald-800 focus-visible:outline-emerald-500',
156
+ outlined: 'text-emerald-700 hover:text-white border border-emerald-700 hover:bg-emerald-700 dark:text-emerald-400 dark:border-emerald-500 focus-visible:outline-emerald-500',
157
157
  plain: 'text-emerald-700 hover:bg-current/10 active:bg-current/15 dark:text-emerald-400 focus-visible:outline-emerald-500',
158
158
  },
159
159
  warning: {
160
- default: 'text-white bg-amber-500 hover:bg-amber-600 focus-visible:outline-amber-500',
161
- outlined: 'text-amber-700 hover:text-white border border-amber-500 hover:bg-amber-500 dark:text-amber-400 dark:border-amber-500 focus-visible:outline-amber-500',
160
+ default: 'text-gray-900 bg-amber-500 hover:bg-amber-400 focus-visible:outline-amber-500',
161
+ outlined: 'text-amber-700 hover:text-gray-900 border border-amber-500 hover:bg-amber-500 dark:text-amber-400 dark:border-amber-500 focus-visible:outline-amber-500',
162
162
  plain: 'text-amber-700 hover:bg-current/10 active:bg-current/15 dark:text-amber-400 focus-visible:outline-amber-500',
163
163
  },
164
164
  };
165
165
  const SIZE_CLASSES = {
166
- xs: { normal: 'h-7 px-2.5 rounded-sm gap-1 text-xs', iconOnly: 'h-7 w-7 p-1 rounded-sm text-xs' },
167
- sm: { normal: 'h-8 px-3 rounded gap-1.5 text-sm', iconOnly: 'h-8 w-8 p-1.5 rounded text-sm' },
168
- md: { normal: 'h-9 px-4 rounded-md gap-2 text-sm', iconOnly: 'h-9 w-9 p-2 rounded-md text-sm' },
166
+ xs: {
167
+ normal: 'min-h-7 px-2.5 py-1 rounded-sm gap-1 text-xs',
168
+ iconOnly: 'h-7 w-7 p-1 rounded-sm text-xs',
169
+ },
170
+ sm: {
171
+ normal: 'min-h-8 px-3 py-1 rounded gap-1.5 text-sm',
172
+ iconOnly: 'h-8 w-8 p-1.5 rounded text-sm',
173
+ },
174
+ md: {
175
+ normal: 'min-h-9 px-4 py-1.5 rounded-md gap-2 text-sm',
176
+ iconOnly: 'h-9 w-9 p-2 rounded-md text-sm',
177
+ },
169
178
  lg: {
170
- normal: 'h-10 px-5 rounded-lg gap-2 text-base',
179
+ normal: 'min-h-10 px-5 py-2 rounded-lg gap-2 text-base',
171
180
  iconOnly: 'h-10 w-10 p-2.5 rounded-lg text-base',
172
181
  },
173
182
  };
@@ -182,12 +191,18 @@ const LOADER_SIZE = {
182
191
  *
183
192
  * Disabled styling is keyed off both the native `disabled` attribute and
184
193
  * `aria-disabled`, so non-button elements rendered via `as` look disabled too.
194
+ *
195
+ * On touch screens an invisible layer makes the tappable area at least 44px,
196
+ * whatever the button's size, without changing how it looks.
185
197
  */
186
- const BASE_BTN_CLASS = 'font-medium inline-flex items-center justify-center shrink-0 cursor-pointer select-none ' +
198
+ const BASE_BTN_CLASS = 'relative font-medium inline-flex items-center justify-center text-center shrink-0 cursor-pointer select-none ' +
187
199
  'transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-150 ease-out ' +
188
200
  'active:scale-[0.98] focus:outline-none ' +
189
201
  'disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none ' +
190
- 'aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-disabled:shadow-none';
202
+ 'aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-disabled:shadow-none ' +
203
+ 'pointer-coarse:after:absolute pointer-coarse:after:top-1/2 pointer-coarse:after:left-1/2 ' +
204
+ 'pointer-coarse:after:-translate-x-1/2 pointer-coarse:after:-translate-y-1/2 ' +
205
+ 'pointer-coarse:after:w-full pointer-coarse:after:min-w-11 pointer-coarse:after:h-full pointer-coarse:after:min-h-11';
191
206
  const Button = forwardRef(({ as, type, ...props }, ref) => {
192
207
  const { className = '', children, theme = 'primary', variant = 'default', size = 'md', leftIcon, rightIcon, fullWidth = false, loading = false, loadingText = '', rounded = false, disabled, iconOnly = false, noOutlineOnFocus = false, active, onClick, ...restProps } = props;
193
208
  const Component = as || 'button';
@@ -239,7 +254,10 @@ const Button = forwardRef(({ as, type, ...props }, ref) => {
239
254
  const elementProps = isNativeButton
240
255
  ? {
241
256
  type: type !== null && type !== void 0 ? type : 'button',
242
- disabled: resolvedDisabled,
257
+ // Not `disabled` while loading: that would drop keyboard focus from the
258
+ // button just pressed. handleClick ignores presses until it's done.
259
+ disabled: Boolean(disabled),
260
+ 'aria-disabled': loading && !disabled ? true : undefined,
243
261
  role,
244
262
  tabIndex,
245
263
  onClick: handleClick,
@@ -269,7 +287,9 @@ const Button = forwardRef(({ as, type, ...props }, ref) => {
269
287
  return buildClassName(BASE_BTN_CLASS, ((_a = THEMED_BTN_CLASS[theme]) === null || _a === void 0 ? void 0 : _a[variant]) || THEMED_BTN_CLASS.primary.default, iconOnly ? sizeObj.iconOnly : sizeObj.normal,
270
288
  // An outline (not a ring) so the offset gap stays transparent on any surface/mode.
271
289
  !noOutlineOnFocus &&
272
- 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-solid', rounded && 'rounded-full', fullWidth && 'w-full', variant === 'default' && 'shadow-xs hover:shadow-none', active && 'ring-2 ring-current', className);
290
+ 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-solid', rounded && 'rounded-full', fullWidth && 'w-full',
291
+ // Secondary default is a flat grey fill; a shadow would bring back the outlined look.
292
+ variant === 'default' && theme !== 'secondary' && 'shadow-xs hover:shadow-none', active && 'ring-2 ring-current', className);
273
293
  }, [theme, variant, sizeObj, iconOnly, noOutlineOnFocus, rounded, fullWidth, active, className]);
274
294
  // The spinner and loading text inherit the button's text colour.
275
295
  const loaderIcon = (jsx(Loader, { "data-testid": "btn-loader-icon", size: LOADER_SIZE[size] || 'xs', className: "text-current" }));
@@ -360,6 +380,86 @@ const useResponsiveValue = (value) => {
360
380
  return value.base;
361
381
  };
362
382
 
383
+ // history.back() lands later, so a drawer opening meanwhile (one replacing another,
384
+ // or React re-running effects under StrictMode) would have its new entry removed
385
+ // instead, and close at once. Removals are counted, and an opening drawer waits for them.
386
+ let pendingBacks = 0;
387
+ const afterBacks = [];
388
+ function settleBack() {
389
+ pendingBacks = Math.max(0, pendingBacks - 1);
390
+ if (pendingBacks === 0)
391
+ afterBacks.splice(0).forEach((run) => run());
392
+ }
393
+ function removeEntry() {
394
+ pendingBacks += 1;
395
+ let settled = false;
396
+ const settle = () => {
397
+ if (settled)
398
+ return;
399
+ settled = true;
400
+ window.removeEventListener('popstate', settle);
401
+ settleBack();
402
+ };
403
+ window.addEventListener('popstate', settle);
404
+ // A back that never reports (nothing to go back to) mustn't hold others up.
405
+ window.setTimeout(settle, 500);
406
+ window.history.back();
407
+ }
408
+ /**
409
+ * While `active`, the browser's back button (and Android's back gesture)
410
+ * closes the drawer instead of leaving the page: opening adds a history entry
411
+ * (keeping the current state, so routers see the same location), and back
412
+ * removes it. Closed any other way, the entry is removed too, but only if it's
413
+ * still the latest one, so a form that saves and then navigates isn't undone.
414
+ */
415
+ function useCloseOnBack(active, onClose) {
416
+ const onCloseRef = React__default.useRef(onClose);
417
+ React__default.useEffect(() => {
418
+ onCloseRef.current = onClose;
419
+ });
420
+ const token = React__default.useId();
421
+ React__default.useEffect(() => {
422
+ if (!active || typeof window === 'undefined')
423
+ return;
424
+ const pushEntry = () => { var _a; return window.history.pushState({ ...((_a = window.history.state) !== null && _a !== void 0 ? _a : {}), drawer: token }, ''); };
425
+ let entryPresent = false;
426
+ let disposed = false;
427
+ const handlePop = () => {
428
+ var _a;
429
+ if (((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
430
+ return;
431
+ entryPresent = false;
432
+ onCloseRef.current();
433
+ // onClose may step back within the drawer instead of closing it; if it's
434
+ // still open afterwards, take back its entry so the next back works too.
435
+ window.setTimeout(() => {
436
+ if (disposed)
437
+ return;
438
+ pushEntry();
439
+ entryPresent = true;
440
+ }, 0);
441
+ };
442
+ const start = () => {
443
+ if (disposed)
444
+ return;
445
+ pushEntry();
446
+ entryPresent = true;
447
+ window.addEventListener('popstate', handlePop);
448
+ };
449
+ if (pendingBacks > 0)
450
+ afterBacks.push(start);
451
+ else
452
+ start();
453
+ return () => {
454
+ var _a;
455
+ disposed = true;
456
+ window.removeEventListener('popstate', handlePop);
457
+ if (entryPresent && ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
458
+ removeEntry();
459
+ };
460
+ }, [active, token]);
461
+ }
462
+
363
463
  const alignmentMap = {
364
464
  center: 'items-center justify-center h-full',
365
465
  start: 'justify-start h-full',
@@ -458,85 +558,6 @@ const Drawer = ({ isOpen, onClose = () => { }, closeOnOutsideClick = true, align
458
558
  : [panelAlignmentMap[align], panelSizeMap[size], panelClass])), "data-layout": fullscreen ? 'fullscreen' : undefined, children: [shouldShowDragHandle && (jsx("div", { className: "w-12 h-1.5 rounded-full bg-gray-300 dark:bg-gray-600 mx-auto my-2.5 shrink-0 cursor-grab", "data-testid": "drawer-drag-handle" })), fullscreen && (jsxs("div", { className: "sticky top-0 z-10 flex h-14 shrink-0 items-center gap-1 border-b border-[var(--ui-border)] bg-white pl-1 pr-3 pt-[env(safe-area-inset-top,0px)] box-content dark:bg-gray-800", children: [jsx(Button, { iconOnly: true, "aria-label": "Close", variant: "plain", theme: "secondary", onClick: onClose, className: "shrink-0", children: jsx(SvgX, { className: "size-5" }) }), title && (jsx(DialogTitle, { as: "h3", className: "min-w-0 flex-1 truncate text-base font-semibold text-gray-900 dark:text-white", children: title })), headerAction && jsx("div", { className: "ml-auto shrink-0", children: headerAction })] })), !fullscreen && showTitleSection && (jsxs("div", { className: buildClassName('space-y-1 py-3 px-4 md:px-6 flex flex-col border-b border-[var(--ui-border)] shrink-0', titleSticky && 'sticky top-0 bg-white dark:bg-gray-800 z-10'), children: [jsxs("div", { className: "flex items-center justify-between gap-3 min-w-0", children: [jsxs("div", { className: "flex items-center gap-2 min-w-0 flex-1", children: [showBackButton && (jsx(Button, { iconOnly: true, "aria-label": "Back", variant: "plain", theme: "secondary", size: "xs", onClick: onClose, children: jsx(SvgChevronLeft, { className: "size-4" }) })), title && (jsx(DialogTitle, { as: "h3", className: buildClassName('text-lg font-semibold text-gray-900 dark:text-white truncate tracking-tight min-w-0', titleClass), children: title }))] }), showCloseButton && (jsx(Button, { iconOnly: true, "aria-label": "Close drawer", variant: "plain", theme: "secondary", size: "xs", onClick: onClose, className: "rounded-full text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 shrink-0", children: jsx(SvgX, { className: "size-4" }) }))] }), description && (jsx("p", { className: buildClassName('text-sm text-gray-500 dark:text-gray-400 font-normal truncate', descriptionClass), children: description }))] })), jsxs("div", { className: buildClassName('flex-1 p-4 md:p-6 space-y-4 min-w-0', contentClass, fullscreen && 'pb-[calc(1rem+env(safe-area-inset-bottom,0px))]'), children: [fullscreen && description && (jsx("p", { className: buildClassName('text-sm text-gray-500 dark:text-gray-400', descriptionClass), children: description })), children] }), !fullscreen && footer && (jsx("div", { className: buildClassName('p-4 border-t border-[var(--ui-border-muted)] bg-white dark:bg-gray-800 shrink-0 min-w-0', footerSticky && 'sticky bottom-0 z-10'), children: footer }))] }) }) })] }));
459
559
  };
460
560
  Drawer.displayName = 'Drawer';
461
- // history.back() lands later, so a drawer opening meanwhile (one replacing another,
462
- // or React re-running effects under StrictMode) would have its new entry removed
463
- // instead, and close at once. Removals are counted, and an opening drawer waits for them.
464
- let pendingBacks = 0;
465
- const afterBacks = [];
466
- function settleBack() {
467
- pendingBacks = Math.max(0, pendingBacks - 1);
468
- if (pendingBacks === 0)
469
- afterBacks.splice(0).forEach((run) => run());
470
- }
471
- function removeEntry() {
472
- pendingBacks += 1;
473
- let settled = false;
474
- const settle = () => {
475
- if (settled)
476
- return;
477
- settled = true;
478
- window.removeEventListener('popstate', settle);
479
- settleBack();
480
- };
481
- window.addEventListener('popstate', settle);
482
- // A back that never reports (nothing to go back to) mustn't hold others up.
483
- window.setTimeout(settle, 500);
484
- window.history.back();
485
- }
486
- /**
487
- * While `active`, the browser's back button (and Android's back gesture)
488
- * closes the drawer instead of leaving the page: opening adds a history entry
489
- * (keeping the current state, so routers see the same location), and back
490
- * removes it. Closed any other way, the entry is removed too, but only if it's
491
- * still the latest one, so a form that saves and then navigates isn't undone.
492
- */
493
- function useCloseOnBack(active, onClose) {
494
- const onCloseRef = React__default.useRef(onClose);
495
- React__default.useEffect(() => {
496
- onCloseRef.current = onClose;
497
- });
498
- const token = React__default.useId();
499
- React__default.useEffect(() => {
500
- if (!active || typeof window === 'undefined')
501
- return;
502
- const pushEntry = () => { var _a; return window.history.pushState({ ...((_a = window.history.state) !== null && _a !== void 0 ? _a : {}), drawer: token }, ''); };
503
- let entryPresent = false;
504
- let disposed = false;
505
- const handlePop = () => {
506
- var _a;
507
- if (((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
508
- return;
509
- entryPresent = false;
510
- onCloseRef.current();
511
- // onClose may step back within the drawer instead of closing it; if it's
512
- // still open afterwards, take back its entry so the next back works too.
513
- window.setTimeout(() => {
514
- if (disposed)
515
- return;
516
- pushEntry();
517
- entryPresent = true;
518
- }, 0);
519
- };
520
- const start = () => {
521
- if (disposed)
522
- return;
523
- pushEntry();
524
- entryPresent = true;
525
- window.addEventListener('popstate', handlePop);
526
- };
527
- if (pendingBacks > 0)
528
- afterBacks.push(start);
529
- else
530
- start();
531
- return () => {
532
- var _a;
533
- disposed = true;
534
- window.removeEventListener('popstate', handlePop);
535
- if (entryPresent && ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.drawer) === token)
536
- removeEntry();
537
- };
538
- }, [active, token]);
539
- }
540
561
 
541
562
  function ActionSheet({ isOpen, onClose, title, description, actions, showCancelButton = true, cancelLabel = 'Cancel', onCancel, closeOnBackdropClick = true, dragHandle = true, panelClass = '', containerClass = '', }) {
542
563
  const handleItemClick = (action) => {
@@ -5227,5 +5248,5 @@ const useIsTabletOrMobile = () => {
5227
5248
  return isMobile || isTablet;
5228
5249
  };
5229
5250
 
5230
- export { Accordion, ActionSheet, Alert, BREAKPOINT_QUERIES, Badge, Banner, BodyText, BottomNavigation, Breadcrumb, Button, ButtonGroup, Card, CardContent, CardDescription, CardFooter, CardHeader, CardMedia, CardTitle, Checkbox, CheckboxGroup, DOTS, DataList, DataTable, DetailedInformation, Dot, Drawer, Dropdown, EmptyState, EmptyTableRow, Flex, FlexItem, FloatingActionButton, Grid, GridCol, HeadingText, Input, Label, Loader, MobileHeader, MobilePicker, MobileStepper, PASSWORD_PLACEHOLDER, PASSWORD_TYPE, Pagination, PasswordInput, PinInput, PullToRefresh, QuantityStepper, Radio, RadioGroup, RadioSwitch, RangeInput, RangeSlider, SegmentedControl, SelectBox, Skeleton, SortIconMap, StatusPill, StickyActionBar, SwipeableRow, SwipeableTabs, Table, TableBody, TableCell, TableFoot, TableHead, TableHeaderCell, TableRow, Tabs, TextContent, Textarea, Toast, ToastProvider, VirtualizedDataTable, WheelPicker, buildClassName, buildInputClass, evaluatePasswordStrength, get, getSortIcon, isArray, isEmpty, nextSortDirection, updateSortQuery, useBreakpoint, useDebounce, useDebounceFn, useIsMobile, useIsTablet, useIsTabletOrMobile, useMediaQuery, usePagination, useResponsiveValue, useRowSelection, useToast };
5251
+ export { Accordion, ActionSheet, Alert, BREAKPOINT_QUERIES, Badge, Banner, BodyText, BottomNavigation, Breadcrumb, Button, ButtonGroup, Card, CardContent, CardDescription, CardFooter, CardHeader, CardMedia, CardTitle, Checkbox, CheckboxGroup, DOTS, DataList, DataTable, DetailedInformation, Dot, Drawer, Dropdown, EmptyState, EmptyTableRow, Flex, FlexItem, FloatingActionButton, Grid, GridCol, HeadingText, Input, Label, Loader, MobileHeader, MobilePicker, MobileStepper, PASSWORD_PLACEHOLDER, PASSWORD_TYPE, Pagination, PasswordInput, PinInput, PullToRefresh, QuantityStepper, Radio, RadioGroup, RadioSwitch, RangeInput, RangeSlider, SegmentedControl, SelectBox, Skeleton, SortIconMap, StatusPill, StickyActionBar, SwipeableRow, SwipeableTabs, Table, TableBody, TableCell, TableFoot, TableHead, TableHeaderCell, TableRow, Tabs, TextContent, Textarea, Toast, ToastProvider, VirtualizedDataTable, WheelPicker, buildClassName, buildInputClass, evaluatePasswordStrength, get, getSortIcon, isArray, isEmpty, nextSortDirection, updateSortQuery, useBreakpoint, useCloseOnBack, useDebounce, useDebounceFn, useIsMobile, useIsTablet, useIsTabletOrMobile, useMediaQuery, usePagination, useResponsiveValue, useRowSelection, useToast };
5231
5252
  //# sourceMappingURL=react-tailwind.es.js.map