@ttoss/ui 1.32.1 → 1.32.2

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/esm/index.js CHANGED
@@ -413,11 +413,133 @@ var CloseButton = /*#__PURE__*/React9.forwardRef(({
413
413
  });
414
414
  CloseButton.displayName = "CloseButton";
415
415
 
416
+ // src/components/InputNumber.tsx
417
+ import { Input as Input2 } from "theme-ui";
418
+ import React10 from "react";
419
+ import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
420
+ var InputNumber = /*#__PURE__*/React10.forwardRef(({
421
+ sx,
422
+ value,
423
+ infoIcon,
424
+ onChange,
425
+ onClickInfoIcon,
426
+ ...inputProps
427
+ }, ref) => {
428
+ const sxProps = React10.useMemo(() => {
429
+ const size = String(typeof value === "undefined" ? 0 : value).length;
430
+ if (inputProps["aria-invalid"] === "true") {
431
+ return {
432
+ width: `calc(139px + ${size > 1 ? size * 10 : 0}px)`,
433
+ textAlign: "left",
434
+ "&[type=number]::-webkit-inner-spin-button, &[type=number]::-webkit-outer-spin-button": {
435
+ "-webkit-appearance": "none",
436
+ margin: 0
437
+ },
438
+ ...sx,
439
+ paddingLeft: "3xl",
440
+ paddingRight: "2xl",
441
+ margin: 0
442
+ };
443
+ }
444
+ return {
445
+ width: `calc(108px + ${size > 1 ? size * 10 : 0}px)`,
446
+ textAlign: "center",
447
+ "&[type=number]::-webkit-inner-spin-button, &[type=number]::-webkit-outer-spin-button": {
448
+ "-webkit-appearance": "none",
449
+ margin: 0
450
+ },
451
+ ...sx,
452
+ paddingLeft: "2xl",
453
+ paddingRight: "2xl",
454
+ margin: 0
455
+ };
456
+ }, [inputProps, value, sx]);
457
+ const handleChangeUp = () => {
458
+ if (inputProps.disabled) {
459
+ return;
460
+ }
461
+ if (typeof value !== "number") {
462
+ onChange(-1);
463
+ return;
464
+ }
465
+ onChange(value - 1);
466
+ };
467
+ const handleChangeDown = () => {
468
+ if (inputProps.disabled) {
469
+ return;
470
+ }
471
+ if (typeof value !== "number") {
472
+ onChange(1);
473
+ return;
474
+ }
475
+ onChange(value + 1);
476
+ };
477
+ return /* @__PURE__ */jsxs9(Flex, {
478
+ sx: {
479
+ width: "fit-content",
480
+ ...sx,
481
+ position: "relative",
482
+ padding: 0,
483
+ border: "none"
484
+ },
485
+ ref,
486
+ "aria-invalid": inputProps["aria-invalid"],
487
+ children: [/* @__PURE__ */jsx13(Input2, {
488
+ ref,
489
+ variant: "forms.inputNumber",
490
+ sx: sxProps,
491
+ type: "number",
492
+ onChange: e => {
493
+ onChange(Number(e.target.value));
494
+ },
495
+ value,
496
+ ...inputProps
497
+ }), /* @__PURE__ */jsx13(Text, {
498
+ sx: {
499
+ position: "absolute",
500
+ alignSelf: "center",
501
+ left: "1rem",
502
+ zIndex: 1,
503
+ cursor: "pointer"
504
+ },
505
+ onClick: handleChangeUp,
506
+ children: /* @__PURE__ */jsx13(Icon, {
507
+ icon: "picker-down"
508
+ })
509
+ }), infoIcon && /* @__PURE__ */jsx13(Text, {
510
+ sx: {
511
+ position: "absolute",
512
+ alignSelf: "center",
513
+ right: "2.5rem",
514
+ zIndex: 1,
515
+ cursor: onClickInfoIcon ? "pointer" : "default"
516
+ },
517
+ onClick: onClickInfoIcon,
518
+ children: /* @__PURE__ */jsx13(Icon, {
519
+ icon: "info"
520
+ })
521
+ }), /* @__PURE__ */jsx13(Text, {
522
+ sx: {
523
+ position: "absolute",
524
+ alignSelf: "center",
525
+ right: "1rem",
526
+ zIndex: 1,
527
+ cursor: "pointer"
528
+ },
529
+ onClick: handleChangeDown,
530
+ children: /* @__PURE__ */jsx13(Icon, {
531
+ icon: "picker-up"
532
+ })
533
+ })]
534
+ });
535
+ });
536
+ InputNumber.displayName = "InputNumber";
537
+
416
538
  // src/components/Stack.tsx
417
- import * as React10 from "react";
418
- import { jsx as jsx13 } from "react/jsx-runtime";
419
- var Stack = /*#__PURE__*/React10.forwardRef((props, ref) => {
420
- return /* @__PURE__ */jsx13(Flex, {
539
+ import * as React11 from "react";
540
+ import { jsx as jsx14 } from "react/jsx-runtime";
541
+ var Stack = /*#__PURE__*/React11.forwardRef((props, ref) => {
542
+ return /* @__PURE__ */jsx14(Flex, {
421
543
  ref,
422
544
  ...props,
423
545
  sx: {
@@ -427,4 +549,4 @@ var Stack = /*#__PURE__*/React10.forwardRef((props, ref) => {
427
549
  });
428
550
  });
429
551
  Stack.displayName = "Stack";
430
- export { Badge, BaseStyles, Box, Button, Card, Checkbox, CloseButton, Container, Divider, Flex, Grid, Heading, HelpText, Icon, IconButton, Image, InfiniteLinearProgress, Input, Label, Progress as LinearProgress, Link, Radio, Select, Slider, Spinner, Stack, Text, Textarea, ThemeProvider, useBreakpointIndex, useResponsiveValue, useTheme };
552
+ export { Badge, BaseStyles, Box, Button, Card, Checkbox, CloseButton, Container, Divider, Flex, Grid, Heading, HelpText, Icon, IconButton, Image, InfiniteLinearProgress, Input, InputNumber, Label, Progress as LinearProgress, Link, Radio, Select, Slider, Spinner, Stack, Text, Textarea, ThemeProvider, useBreakpointIndex, useResponsiveValue, useTheme };
package/dist/index.d.ts CHANGED
@@ -68,10 +68,18 @@ type CloseButtonProps = ButtonProps$1 & {
68
68
  };
69
69
  declare const CloseButton: React__default.ForwardRefExoticComponent<Omit<CloseButtonProps, "ref"> & React__default.RefAttributes<HTMLButtonElement>>;
70
70
 
71
+ type InputNumberProps = Omit<InputProps$1, 'type' | 'variant' | 'onChange'> & {
72
+ onChange: (value: number) => void;
73
+ value?: number;
74
+ infoIcon?: boolean;
75
+ onClickInfoIcon?: () => void;
76
+ };
77
+ declare const InputNumber: React__default.ForwardRefExoticComponent<Omit<InputNumberProps, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
78
+
71
79
  type StackProps = FlexProps;
72
80
  /**
73
81
  * A component that renders its children in a column.
74
82
  */
75
83
  declare const Stack: React.ForwardRefExoticComponent<theme_ui.BoxProps & React.RefAttributes<HTMLElement>>;
76
84
 
77
- export { Badge, BadgeProps, Button, ButtonProps, CloseButton, CloseButtonProps, HelpText, HelpTextProps, Icon, IconButton, IconProps, IconType, InfiniteLinearProgress, Input, InputProps, Label, LabelProps, Select, Stack, StackProps, Textarea, TextareaProps, ThemeProvider, ThemeProviderProps, useTheme };
85
+ export { Badge, BadgeProps, Button, ButtonProps, CloseButton, CloseButtonProps, HelpText, HelpTextProps, Icon, IconButton, IconProps, IconType, InfiniteLinearProgress, Input, InputNumber, InputNumberProps, InputProps, Label, LabelProps, Select, Stack, StackProps, Textarea, TextareaProps, ThemeProvider, ThemeProviderProps, useTheme };
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
39
39
  var src_exports = {};
40
40
  __export(src_exports, {
41
41
  Badge: () => Badge,
42
- BaseStyles: () => import_theme_ui26.BaseStyles,
42
+ BaseStyles: () => import_theme_ui27.BaseStyles,
43
43
  Box: () => import_theme_ui4.Box,
44
44
  Button: () => Button,
45
45
  Card: () => import_theme_ui6.Card,
@@ -56,6 +56,7 @@ __export(src_exports, {
56
56
  Image: () => import_theme_ui11.Image,
57
57
  InfiniteLinearProgress: () => InfiniteLinearProgress,
58
58
  Input: () => Input,
59
+ InputNumber: () => InputNumber,
59
60
  Label: () => Label,
60
61
  LinearProgress: () => import_theme_ui15.Progress,
61
62
  Link: () => import_theme_ui14.Link,
@@ -72,7 +73,7 @@ __export(src_exports, {
72
73
  useTheme: () => useTheme
73
74
  });
74
75
  module.exports = __toCommonJS(src_exports);
75
- var import_theme_ui26 = require("theme-ui");
76
+ var import_theme_ui27 = require("theme-ui");
76
77
  var import_match_media = require("@theme-ui/match-media");
77
78
 
78
79
  // src/theme/ThemeProvider.tsx
@@ -484,11 +485,133 @@ var CloseButton = import_react6.default.forwardRef(({
484
485
  });
485
486
  CloseButton.displayName = "CloseButton";
486
487
 
487
- // src/components/Stack.tsx
488
- var React10 = __toESM(require("react"));
488
+ // src/components/InputNumber.tsx
489
+ var import_theme_ui26 = require("theme-ui");
490
+ var import_react7 = __toESM(require("react"));
489
491
  var import_jsx_runtime13 = require("react/jsx-runtime");
490
- var Stack = React10.forwardRef((props, ref) => {
491
- return /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_theme_ui8.Flex, {
492
+ var InputNumber = import_react7.default.forwardRef(({
493
+ sx,
494
+ value,
495
+ infoIcon,
496
+ onChange,
497
+ onClickInfoIcon,
498
+ ...inputProps
499
+ }, ref) => {
500
+ const sxProps = import_react7.default.useMemo(() => {
501
+ const size = String(typeof value === "undefined" ? 0 : value).length;
502
+ if (inputProps["aria-invalid"] === "true") {
503
+ return {
504
+ width: `calc(139px + ${size > 1 ? size * 10 : 0}px)`,
505
+ textAlign: "left",
506
+ "&[type=number]::-webkit-inner-spin-button, &[type=number]::-webkit-outer-spin-button": {
507
+ "-webkit-appearance": "none",
508
+ margin: 0
509
+ },
510
+ ...sx,
511
+ paddingLeft: "3xl",
512
+ paddingRight: "2xl",
513
+ margin: 0
514
+ };
515
+ }
516
+ return {
517
+ width: `calc(108px + ${size > 1 ? size * 10 : 0}px)`,
518
+ textAlign: "center",
519
+ "&[type=number]::-webkit-inner-spin-button, &[type=number]::-webkit-outer-spin-button": {
520
+ "-webkit-appearance": "none",
521
+ margin: 0
522
+ },
523
+ ...sx,
524
+ paddingLeft: "2xl",
525
+ paddingRight: "2xl",
526
+ margin: 0
527
+ };
528
+ }, [inputProps, value, sx]);
529
+ const handleChangeUp = () => {
530
+ if (inputProps.disabled) {
531
+ return;
532
+ }
533
+ if (typeof value !== "number") {
534
+ onChange(-1);
535
+ return;
536
+ }
537
+ onChange(value - 1);
538
+ };
539
+ const handleChangeDown = () => {
540
+ if (inputProps.disabled) {
541
+ return;
542
+ }
543
+ if (typeof value !== "number") {
544
+ onChange(1);
545
+ return;
546
+ }
547
+ onChange(value + 1);
548
+ };
549
+ return /* @__PURE__ */(0, import_jsx_runtime13.jsxs)(import_theme_ui8.Flex, {
550
+ sx: {
551
+ width: "fit-content",
552
+ ...sx,
553
+ position: "relative",
554
+ padding: 0,
555
+ border: "none"
556
+ },
557
+ ref,
558
+ "aria-invalid": inputProps["aria-invalid"],
559
+ children: [/* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_theme_ui26.Input, {
560
+ ref,
561
+ variant: "forms.inputNumber",
562
+ sx: sxProps,
563
+ type: "number",
564
+ onChange: e => {
565
+ onChange(Number(e.target.value));
566
+ },
567
+ value,
568
+ ...inputProps
569
+ }), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_theme_ui16.Text, {
570
+ sx: {
571
+ position: "absolute",
572
+ alignSelf: "center",
573
+ left: "1rem",
574
+ zIndex: 1,
575
+ cursor: "pointer"
576
+ },
577
+ onClick: handleChangeUp,
578
+ children: /* @__PURE__ */(0, import_jsx_runtime13.jsx)(Icon, {
579
+ icon: "picker-down"
580
+ })
581
+ }), infoIcon && /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_theme_ui16.Text, {
582
+ sx: {
583
+ position: "absolute",
584
+ alignSelf: "center",
585
+ right: "2.5rem",
586
+ zIndex: 1,
587
+ cursor: onClickInfoIcon ? "pointer" : "default"
588
+ },
589
+ onClick: onClickInfoIcon,
590
+ children: /* @__PURE__ */(0, import_jsx_runtime13.jsx)(Icon, {
591
+ icon: "info"
592
+ })
593
+ }), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_theme_ui16.Text, {
594
+ sx: {
595
+ position: "absolute",
596
+ alignSelf: "center",
597
+ right: "1rem",
598
+ zIndex: 1,
599
+ cursor: "pointer"
600
+ },
601
+ onClick: handleChangeDown,
602
+ children: /* @__PURE__ */(0, import_jsx_runtime13.jsx)(Icon, {
603
+ icon: "picker-up"
604
+ })
605
+ })]
606
+ });
607
+ });
608
+ InputNumber.displayName = "InputNumber";
609
+
610
+ // src/components/Stack.tsx
611
+ var React11 = __toESM(require("react"));
612
+ var import_jsx_runtime14 = require("react/jsx-runtime");
613
+ var Stack = React11.forwardRef((props, ref) => {
614
+ return /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_theme_ui8.Flex, {
492
615
  ref,
493
616
  ...props,
494
617
  sx: {
@@ -518,6 +641,7 @@ Stack.displayName = "Stack";
518
641
  Image,
519
642
  InfiniteLinearProgress,
520
643
  Input,
644
+ InputNumber,
521
645
  Label,
522
646
  LinearProgress,
523
647
  Link,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/ui",
3
- "version": "1.32.1",
3
+ "version": "1.32.2",
4
4
  "description": "Primitive layout, typographic, and other components for styling applications.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ttoss",
@@ -23,7 +23,7 @@
23
23
  "@emotion/react": "^11.10.6",
24
24
  "@iconify-icon/react": "^1.0.7",
25
25
  "@theme-ui/match-media": "^0.15.7",
26
- "@ttoss/theme": "^1.4.16",
26
+ "@ttoss/theme": "^1.4.17",
27
27
  "theme-ui": "^0.15.7"
28
28
  },
29
29
  "peerDependencies": {
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "81c9da91988b338a6449d84b4dfc183ccf9ed941"
51
+ "gitHead": "0ea6f4641c1d97631f38c72da681a9e2dc54d0b7"
52
52
  }
@@ -0,0 +1,146 @@
1
+ import { Flex, Icon, Text } from '..';
2
+ import { Input, type InputProps as InputPropsUI } from 'theme-ui';
3
+ import React from 'react';
4
+
5
+ export type InputNumberProps = Omit<
6
+ InputPropsUI,
7
+ 'type' | 'variant' | 'onChange'
8
+ > & {
9
+ onChange: (value: number) => void;
10
+ value?: number;
11
+ infoIcon?: boolean;
12
+ onClickInfoIcon?: () => void;
13
+ };
14
+
15
+ export const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>(
16
+ ({ sx, value, infoIcon, onChange, onClickInfoIcon, ...inputProps }, ref) => {
17
+ const sxProps: InputPropsUI['sx'] = React.useMemo(() => {
18
+ const size = String(typeof value === 'undefined' ? 0 : value).length;
19
+
20
+ if (inputProps['aria-invalid'] === 'true') {
21
+ return {
22
+ width: `calc(139px + ${size > 1 ? size * 10 : 0}px)`,
23
+ textAlign: 'left',
24
+ '&[type=number]::-webkit-inner-spin-button, &[type=number]::-webkit-outer-spin-button':
25
+ {
26
+ '-webkit-appearance': 'none',
27
+ margin: 0,
28
+ },
29
+ ...sx,
30
+ paddingLeft: '3xl',
31
+ paddingRight: '2xl',
32
+ margin: 0,
33
+ };
34
+ }
35
+
36
+ return {
37
+ width: `calc(108px + ${size > 1 ? size * 10 : 0}px)`,
38
+ textAlign: 'center',
39
+ '&[type=number]::-webkit-inner-spin-button, &[type=number]::-webkit-outer-spin-button':
40
+ {
41
+ '-webkit-appearance': 'none',
42
+ margin: 0,
43
+ },
44
+ ...sx,
45
+ paddingLeft: '2xl',
46
+ paddingRight: '2xl',
47
+ margin: 0,
48
+ };
49
+ }, [inputProps, value, sx]);
50
+
51
+ const handleChangeUp = () => {
52
+ if (inputProps.disabled) {
53
+ return;
54
+ }
55
+
56
+ if (typeof value !== 'number') {
57
+ onChange(-1);
58
+ return;
59
+ }
60
+
61
+ onChange(value - 1);
62
+ };
63
+
64
+ const handleChangeDown = () => {
65
+ if (inputProps.disabled) {
66
+ return;
67
+ }
68
+
69
+ if (typeof value !== 'number') {
70
+ onChange(1);
71
+ return;
72
+ }
73
+
74
+ onChange(value + 1);
75
+ };
76
+
77
+ return (
78
+ <Flex
79
+ sx={{
80
+ width: 'fit-content',
81
+ ...sx,
82
+ position: 'relative',
83
+ padding: 0,
84
+ border: 'none',
85
+ }}
86
+ ref={ref}
87
+ aria-invalid={inputProps['aria-invalid']}
88
+ >
89
+ <Input
90
+ ref={ref}
91
+ variant="forms.inputNumber"
92
+ sx={sxProps}
93
+ type="number"
94
+ onChange={(e) => {
95
+ onChange(Number(e.target.value));
96
+ }}
97
+ value={value}
98
+ {...inputProps}
99
+ />
100
+
101
+ <Text
102
+ sx={{
103
+ position: 'absolute',
104
+ alignSelf: 'center',
105
+ left: '1rem',
106
+ zIndex: 1,
107
+ cursor: 'pointer',
108
+ }}
109
+ onClick={handleChangeUp}
110
+ >
111
+ <Icon icon="picker-down" />
112
+ </Text>
113
+
114
+ {infoIcon && (
115
+ <Text
116
+ sx={{
117
+ position: 'absolute',
118
+ alignSelf: 'center',
119
+ right: '2.5rem',
120
+ zIndex: 1,
121
+ cursor: onClickInfoIcon ? 'pointer' : 'default',
122
+ }}
123
+ onClick={onClickInfoIcon}
124
+ >
125
+ <Icon icon="info" />
126
+ </Text>
127
+ )}
128
+
129
+ <Text
130
+ sx={{
131
+ position: 'absolute',
132
+ alignSelf: 'center',
133
+ right: '1rem',
134
+ zIndex: 1,
135
+ cursor: 'pointer',
136
+ }}
137
+ onClick={handleChangeDown}
138
+ >
139
+ <Icon icon="picker-up" />
140
+ </Text>
141
+ </Flex>
142
+ );
143
+ }
144
+ );
145
+
146
+ InputNumber.displayName = 'InputNumber';
package/src/index.ts CHANGED
@@ -34,4 +34,5 @@ export { Textarea, type TextareaProps } from './components/Textarea';
34
34
  export { Container, type ContainerProps } from './components/Container';
35
35
  export { HelpText, type HelpTextProps } from './components/HelpText';
36
36
  export { CloseButton, type CloseButtonProps } from './components/CloseButton';
37
+ export { InputNumber, type InputNumberProps } from './components/InputNumber';
37
38
  export { Stack, type StackProps } from './components/Stack';