Skip to content

Commit 99f03c3

Browse files
committed
feat: add fullWidth and placeholder props to FormInputField and update styling
1 parent 8799ef6 commit 99f03c3

File tree

13 files changed

+130
-62
lines changed

13 files changed

+130
-62
lines changed

packages/react-ui/src/components/button/button.styles.ts

+30-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export const buttonStyles = tv({
2424
neutral: "focus-visible:outline-bg-neutral-emphasis/70",
2525
},
2626
size: {
27-
xs: "text-xs",
28-
sm: "text-sm",
29-
md: "text-sm",
30-
lg: "text-base",
31-
xl: "text-base",
27+
xs: "",
28+
sm: "",
29+
md: "",
30+
lg: "",
31+
xl: "",
3232
},
3333
disabled: {
3434
true: "opacity-60",
@@ -287,7 +287,6 @@ export const buttonStyles = tv({
287287
disabled: false,
288288
className: "hover:text-fg-neutral-hovered active:text-fg-neutral-pressed",
289289
},
290-
291290
{
292291
iconOnly: false,
293292
noPadding: false,
@@ -343,6 +342,31 @@ export const buttonStyles = tv({
343342
noPadding: false,
344343
className: "h-11",
345344
},
345+
{
346+
size: "xs",
347+
iconOnly: false,
348+
className: "text-xs",
349+
},
350+
{
351+
size: "sm",
352+
iconOnly: false,
353+
className: "text-sm",
354+
},
355+
{
356+
size: "md",
357+
iconOnly: false,
358+
className: "text-sm",
359+
},
360+
{
361+
size: "lg",
362+
iconOnly: false,
363+
className: "text-base",
364+
},
365+
{
366+
size: "xl",
367+
iconOnly: false,
368+
className: "text-base",
369+
},
346370
],
347371
});
348372

packages/react-ui/src/components/close-button/close-button.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export type CloseButtonProps = {
2323
*/
2424
size?: string;
2525

26+
/**
27+
* 按钮圆角
28+
* @default true
29+
*/
30+
radius?: number | boolean | "full";
31+
2632
/**
2733
* 无内边距
2834
* @default false
@@ -38,6 +44,7 @@ export const CloseButton = (props: PrimitiveProps<"button", CloseButtonProps, "t
3844
variant = "ghost",
3945
color = "neutral",
4046
size = "1.5em",
47+
radius = "full",
4148
children,
4249
...rest
4350
} = props;
@@ -50,12 +57,12 @@ export const CloseButton = (props: PrimitiveProps<"button", CloseButtonProps, "t
5057
color={color}
5158
iconOnly
5259
noPadding
53-
radius={"full"}
60+
radius={radius}
5461
aria-label="关闭"
55-
className={tx("leading-none", !noPadding && "p-1", className)}
62+
className={tx(!noPadding && "p-1", className)}
5663
{...rest}
5764
>
58-
{children || <CloseIcon size={size} />}
65+
{children || <CloseIcon className={"-mb-[.1em]"} size={size} />}
5966
</Button>
6067
);
6168
};

packages/react-ui/src/components/input/input.styles.ts

+42-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
1+
import { tv } from "../../utils";
2+
3+
export const inputHeightStyles = {
4+
xs: "py-[5px] min-h-7",
5+
sm: "py-[5px] min-h-8",
6+
md: "py-[5px] min-h-9",
7+
lg: "py-[7px] min-h-10",
8+
xl: "py-[7px] min-h-11",
9+
};
10+
111
export const inputSizeStyles = {
2-
xs: "px-2.5 py-[5px]",
3-
sm: "px-3 py-[5px]",
4-
md: "px-3.5 py-[5px]",
5-
lg: "px-4 py-[7px]",
6-
xl: "px-5 py-[7px]",
12+
xs: "px-2.5",
13+
sm: "px-2.5",
14+
md: "px-3",
15+
lg: "px-3.5",
16+
xl: "px-3.5",
717
};
818

19+
export const inputStyles = tv({
20+
base: [
21+
"relative inline-flex items-center rounded-md border",
22+
"outline-1 outline-transparent transition-colors",
23+
"focus-within:border-bg-primary-emphasis focus-within:outline-bg-primary-emphasis/70",
24+
],
25+
variants: {
26+
disabled: {
27+
true: "opacity-60",
28+
},
29+
invalid: {
30+
true: "border-bd-invalid",
31+
false: "border-bd-normal",
32+
},
33+
fullWidth: {
34+
true: "w-full",
35+
},
36+
},
37+
compoundVariants: [
38+
{
39+
disabled: false,
40+
invalid: false,
41+
className: "not-focus-within:hover:border-bd-hovered",
42+
},
43+
],
44+
});
45+
946
export type InputSize = keyof typeof inputSizeStyles;
1047

1148
export const inputAffixDefaultSizes = {

packages/react-ui/src/components/input/input.tsx

+11-27
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ import { type ChangeEvent, type CSSProperties, type ReactNode, useRef } from "re
22
import { useControllableState, useMergeRefs } from "../../hooks";
33
import type { PrimitiveProps } from "../../primitives";
44
import { inputTextShareStyles } from "../../shared/styles";
5-
import type { FormFieldProps } from "../../shared/types";
5+
import type { FormInputFieldProps } from "../../shared/types";
66
import { tx } from "../../utils";
77
import { InputAffix } from "./input-affix";
88
import { type InputGroupContextValue, useInputGroup } from "./input-group-context";
9-
import { inputAffixDefaultSizes, inputGroupStyles, inputSizeStyles } from "./input.styles";
9+
import {
10+
inputAffixDefaultSizes,
11+
inputGroupStyles,
12+
inputHeightStyles,
13+
inputSizeStyles,
14+
inputStyles,
15+
} from "./input.styles";
1016

1117
export type InputProps = Partial<InputGroupContextValue> &
12-
FormFieldProps & {
18+
FormInputFieldProps & {
1319
/**
1420
* 可控值
1521
*/
@@ -26,23 +32,6 @@ export type InputProps = Partial<InputGroupContextValue> &
2632
*/
2733
onChange?: (value: string | number) => void;
2834

29-
/**
30-
* 是否无效
31-
* @default false
32-
*/
33-
invalid?: boolean;
34-
35-
/**
36-
* 占位符文本
37-
*/
38-
placeholder?: string;
39-
40-
/**
41-
* 是否全宽度
42-
* @default false
43-
*/
44-
fullWidth?: boolean;
45-
4635
/**
4736
* 前置元素
4837
*/
@@ -118,14 +107,8 @@ export const Input = (props: PrimitiveProps<"input", InputProps, "children">) =>
118107
return (
119108
<div
120109
className={tx(
121-
"relative inline-flex h-fit items-center rounded-md border",
122-
"outline-1 outline-transparent transition-colors",
123-
"focus-within:border-bg-primary-emphasis focus-within:outline-bg-primary-emphasis/70",
124-
fullWidth && "w-full",
110+
inputStyles({ disabled, invalid, fullWidth }),
125111
group && [inputGroupStyles, "focus-within:z-1"],
126-
invalid ? "border-bd-invalid" : "border-bd-normal",
127-
!disabled && !invalid && "not-focus-within:hover:border-bd-hovered",
128-
disabled && "opacity-60",
129112
className,
130113
)}
131114
style={
@@ -143,6 +126,7 @@ export const Input = (props: PrimitiveProps<"input", InputProps, "children">) =>
143126
"bg-bg-normal rounded-md transition-colors",
144127
disabled && "bg-bg-subtlest/60",
145128
inputSizeStyles[size],
129+
inputHeightStyles[size],
146130
inputTextShareStyles[size],
147131
prefix && "ps-(--pw)",
148132
suffix && "pe-(--sw)",

packages/react-ui/src/components/number-input/number-input.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type NumberInputProps = Omit<
2323
* onChange 回调
2424
*/
2525
onChange?: (value: number | undefined) => void;
26+
2627
/**
2728
* 最小值
2829
* @default Number.MIN_SAFE_INTEGER

packages/react-ui/src/components/select/native-select.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import type { PrimitiveProps } from "../../primitives";
22
import { AngleDownIcon } from "../../shared/icons";
33
import { inputTextShareStyles } from "../../shared/styles";
4-
import type { FormFieldProps } from "../../shared/types";
4+
import type { FormInputFieldProps } from "../../shared/types";
55
import { tx } from "../../utils";
66
import { type SelectSize, selectSizeStyles } from "./select.styles";
77

8-
export type NativeSelectProps = FormFieldProps & {
9-
/**
10-
* 是否无效
11-
* @default false
12-
*/
13-
invalid?: boolean;
14-
8+
export type NativeSelectProps = FormInputFieldProps & {
159
/**
1610
* 大小
1711
* @default 'md'

packages/react-ui/src/shared/types.ts

+19
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,22 @@ export type FormFieldProps = {
8989
*/
9090
readOnly?: boolean;
9191
};
92+
93+
export type FormInputFieldProps = FormFieldProps & {
94+
/**
95+
* 是否无效
96+
* @default false
97+
*/
98+
invalid?: boolean;
99+
100+
/**
101+
* 占位符文本
102+
*/
103+
placeholder?: string;
104+
105+
/**
106+
* 是否全宽度
107+
* @default false
108+
*/
109+
fullWidth?: boolean;
110+
};

website/src/components/color-mode-toggle.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const ColorModeToggle = () => {
3737
<Button aria-label={"颜色模式"} color={"neutral"} variant={"ghost"} size={"sm"} iconOnly {...props} />
3838
)}
3939
>
40-
<SpriteIcon size={"1.5em"} name={colorModes[colorMode]?.icon} />
40+
<SpriteIcon size={"1.325em"} name={colorModes[colorMode]?.icon} />
4141
</DropdownMenuTrigger>
4242
<DropdownMenuContent className={"text-sm"}>
4343
<DropdownMenuArrow />

website/src/components/site-navbar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const SiteNavbar = () => {
7171
rel={"noreferrer"}
7272
{...props}
7373
>
74-
<SpriteIcon size={"1.5em"} name={"github"} />
74+
<SpriteIcon size={"1.325em"} name={"github"} />
7575
</a>
7676
)}
7777
{...props}

website/src/components/sprite-icon.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const SpriteIcon = (props: SpriteIconProps) => {
1212
const { name, size = "1em", color, className } = props;
1313

1414
return (
15-
<svg style={{ width: size }} className={tx("mb-[-.1em] aspect-square", className)}>
15+
<svg style={{ width: size }} className={tx("aspect-square", className)}>
1616
<use color={color} href={`${spriteIcons}#${name}`} />
1717
</svg>
1818
);

website/src/routes/_index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function Index() {
2222
size={"xl"}
2323
render={(props) => (
2424
<a {...props} href="https://github.com/huijiewei/resolid-react-ui" target="_blank" rel="noreferrer">
25-
<SpriteIcon size={"1.5em"} className={"me-2"} name={"github"} />
25+
<SpriteIcon size={"1.325em"} className={"me-2"} name={"github"} />
2626
Github
2727
</a>
2828
)}

website/src/routes/docs/_mdx/components/input.mdx

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ import { Input } from "@resolid/react-ui";
6565

6666
export default function App() {
6767
return (
68-
<div className={"flex flex-row items-center gap-3"}>
69-
<Input size={"xs"} defaultValue={"XS 超小"} placeholder={"XS 超小"} />
70-
<Input size={"sm"} defaultValue={"SM 小型"} />
71-
<Input defaultValue={"普通输入框"} />
72-
<Input size={"lg"} defaultValue={"LG 大型"} />
73-
<Input size={"xl"} defaultValue={"XL 超大"} />
68+
<div className={"flex flex-col gap-3"}>
69+
<Input size={"xs"} placeholder={"XS 超小"} />
70+
<Input size={"sm"} placeholder={"SM 小型"} />
71+
<Input placeholder={"默认大小"} />
72+
<Input size={"lg"} placeholder={"LG 大型"} />
73+
<Input size={"xl"} placeholder={"XL 超大"} />
7474
</div>
7575
);
7676
}
@@ -99,7 +99,7 @@ export default function App() {
9999
size={"xs"}
100100
iconOnly
101101
>
102-
<SpriteIcon size={"1.375em"} name={"search"} />
102+
<SpriteIcon size={"1.125em"} name={"search"} />
103103
</Button>
104104
}
105105
/>

website/src/routes/docs/_mdx/components/tabs.mdx

+4-2
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ export default function App() {
197197
{tabs.map((tab) => {
198198
return (
199199
<TabsTab
200-
render={(props) => <span {...props} />}
200+
render={(props) => <div {...props} />}
201201
key={tab.id}
202202
value={tab.id}
203-
className={"active:bg-bg-subtle select-none rounded-md pe-1 ps-3"}
203+
className={
204+
"active:bg-bg-subtle inline-flex select-none items-center rounded-md pe-1 ps-3"
205+
}
204206
>
205207
{tab.title}
206208
<CloseButton

0 commit comments

Comments
 (0)