@vygruppen/spor-react 10.2.0 → 10.4.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.
@@ -0,0 +1,119 @@
1
+ import { StyleFunctionProps } from "@chakra-ui/theme-tools";
2
+ import { baseBackground, baseBorder, baseText } from "./base-utils";
3
+ import { floatingBackground, floatingBorder } from "./floating-utils";
4
+ import { InputState } from "./types";
5
+ import { focusVisibleStyles } from "./focus-utils";
6
+ import { surface } from "./surface-utils";
7
+
8
+ export function inputVariant(state: InputState, props: StyleFunctionProps) {
9
+ switch (state) {
10
+ case "base":
11
+ return {
12
+ ...baseBackground("default", props),
13
+ ...baseBorder("default", props),
14
+ _hover: {
15
+ ...baseBorder("hover", props),
16
+ },
17
+ _active: {
18
+ ...baseBackground("active", props),
19
+ ...baseBorder("default", props),
20
+ },
21
+ _selected: {
22
+ ...baseBackground("selected", props),
23
+ ...baseBorder("selected", props),
24
+ },
25
+ };
26
+ case "floating":
27
+ return {
28
+ boxShadow: "sm",
29
+ ...floatingBackground("default", props),
30
+ ...floatingBorder("default", props),
31
+
32
+ _hover: {
33
+ ...floatingBorder("hover", props),
34
+ ...floatingBackground("hover", props),
35
+ },
36
+ _active: {
37
+ ...floatingBorder("active", props),
38
+ ...floatingBackground("active", props),
39
+ },
40
+ _selected: {
41
+ ...floatingBorder("selected", props),
42
+ ...floatingBackground("selected", props),
43
+ },
44
+ };
45
+ case "default":
46
+ default:
47
+ return {
48
+ ...baseBackground("default", props),
49
+ ...baseBorder("default", props),
50
+ _hover: {
51
+ ...baseBorder("hover", props),
52
+ },
53
+ _active: {
54
+ ...baseBackground("active", props),
55
+ ...baseBorder("default", props),
56
+ },
57
+ _selected: {
58
+ ...baseBackground("selected", props),
59
+ ...baseBorder("selected", props),
60
+ },
61
+ };
62
+ }
63
+ }
64
+
65
+ export const inputBaseStyle = (props: StyleFunctionProps) => ({
66
+ field: {
67
+ appearance: "none",
68
+ width: "100%",
69
+ outline: "none",
70
+ border: 0,
71
+ borderRadius: "sm",
72
+ transitionProperty: "common",
73
+ transitionDuration: "fast",
74
+ position: "relative",
75
+ paddingX: 3,
76
+ height: 8,
77
+ fontSize: "mobile.md",
78
+ _focusVisible: {
79
+ ...focusVisibleStyles(props)._focusVisible,
80
+ outlineOffset: 0,
81
+ },
82
+ _disabled: {
83
+ ...surface("disabled", props),
84
+ ...baseBorder("disabled", props),
85
+ pointerEvents: "none",
86
+ },
87
+ _invalid: {
88
+ ...baseBorder("invalid", props),
89
+ _hover: {
90
+ ...baseBorder("hover", props),
91
+ },
92
+ },
93
+ " + label": {
94
+ fontSize: ["mobile.sm", "desktop.sm"],
95
+ top: "2px",
96
+ left: props.paddingLeft || props.pl || 3,
97
+ zIndex: 2,
98
+ position: "absolute",
99
+ marginY: 2,
100
+ transition: ".1s ease-out",
101
+ transformOrigin: "top left",
102
+ cursor: "text",
103
+ },
104
+ "&:not(:placeholder-shown)": {
105
+ paddingTop: "1rem",
106
+ "& + label": {
107
+ transform: "scale(0.825) translateY(-10px)",
108
+ },
109
+ },
110
+ },
111
+ element: {
112
+ height: "100%",
113
+ },
114
+ group: {
115
+ ":has(:disabled)": {
116
+ ...baseText("disabled", props),
117
+ },
118
+ },
119
+ });
@@ -9,5 +9,7 @@ export type State =
9
9
  | "error"
10
10
  | "focus";
11
11
 
12
+ export type InputState = "base" | "floating" | "default";
13
+
12
14
  // Helper type to extract subset of union types
13
15
  export type Subset<T, U extends T> = T extends U ? T : never;