Skip to content

Commit 29a6aaa

Browse files
committed
feat: Adds appearanceVariant prop that reflects chackra-ui variants from inputs and selects
fix: Extra padding when flushed styled was applied This feature allow users to use different apperances in the same project
1 parent 1eff922 commit 29a6aaa

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Check out these demos:
3434
- [Extra Props](#extra-props)
3535
- [`size`](#size--options-sm-md-lg--default-md)
3636
- [`colorScheme`](#colorscheme)
37+
- [`appearanceVariant`](#appearanceVariant)
3738
- [`tagVariant`](#tagvariant--options-subtle-solid-outline--default-subtle)
3839
- [`isInvalid`](#isinvalid--default-false)
3940
- [`focusBorderColor` / `errorBorderColor`](#focusbordercolor--default-blue500--errorbordercolor--default-red500)
@@ -141,6 +142,16 @@ return (
141142
);
142143
```
143144

145+
#### `appearanceVariant`
146+
147+
You can set `outline`, `unstyled`, `flushed` or `filled`, which will reflect the same styles of Chakra-Ui select possible appearances [Check chakra-ui variants styles](https://chakra-ui.com/docs/components/select#changing-the-appearance)!
148+
149+
```js
150+
return (
151+
<Select appearanceVariant="flushed" />
152+
);
153+
```
154+
144155
#### `tagVariant` — Options: `subtle`, `solid`, `outline` — Default: `subtle`
145156

146157
You can pass the `tagVariant` prop with either `subtle`, `solid`, or `outline` (default is `subtle`). These will reflect the `variant` prop available on the [Chakra `<Tag />` component](https://chakra-ui.com/docs/components/tag/props).

src/chakra-components/containers.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from "react";
22
import { Box } from "@chakra-ui/layout";
33
import type { CSSObject } from "@chakra-ui/system";
4+
import { useMultiStyleConfig } from "@chakra-ui/system";
45
import type {
56
ContainerProps,
67
GroupBase,
78
IndicatorsContainerProps,
89
ValueContainerProps,
910
} from "react-select";
10-
import type { SizeProps } from "../types";
1111

1212
export const SelectContainer = <
1313
Option,
@@ -72,20 +72,22 @@ export const ValueContainer = <
7272
isMulti,
7373
hasValue,
7474
innerProps,
75-
selectProps: { size, chakraStyles },
75+
selectProps: { size, chakraStyles, appearanceVariant: variant },
7676
} = props;
7777

78-
const px: SizeProps = {
79-
sm: "0.75rem",
80-
md: "1rem",
81-
lg: "1rem",
82-
};
78+
// Getting the css from input instead of select
79+
// to fit better with the search input feature
80+
81+
const chakraInputConfig = useMultiStyleConfig("Input", {
82+
size,
83+
variant,
84+
});
8385

8486
const initialSx: CSSObject = {
8587
display: "flex",
8688
alignItems: "center",
8789
flex: 1,
88-
padding: `0.125rem ${px[size || "md"]}`,
90+
px: chakraInputConfig.field.px,
8991
flexWrap: "wrap",
9092
WebkitOverflowScrolling: "touch",
9193
position: "relative",

src/chakra-components/control.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ const Control = <
3737
chakraStyles,
3838
focusBorderColor,
3939
errorBorderColor,
40+
appearanceVariant: variant,
4041
},
4142
} = props;
4243

4344
const inputStyles = useMultiStyleConfig("Input", {
4445
focusBorderColor,
4546
errorBorderColor,
4647
size,
48+
variant,
4749
});
4850

4951
const heights: SizeProps = {

src/module-augmentation.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { CSSObject } from "@chakra-ui/system";
33
import type { GroupBase } from "react-select";
44
import type {
5+
AppearanceVariant,
56
ChakraStylesConfig,
67
SelectedOptionStyle,
78
Size,
@@ -75,6 +76,16 @@ declare module "react-select/dist/declarations/src/Select" {
7576
*/
7677
colorScheme?: string;
7778

79+
/**
80+
* The `appearanceVariant` prop that changes the select main style
81+
*
82+
* Options: "outline" | "unstyled" | "flushed" | "filled"
83+
*
84+
* @defaultValue `outline`
85+
* @see {@link https://chakra-ui.com/docs/components/select#changing-the-appearance}
86+
*/
87+
appearanceVariant?: AppearanceVariant;
88+
7889
/**
7990
* The `variant` prop that will be forwarded to your `MultiValue` component
8091
* which is represented by a chakra `Tag`

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface SizeProps<PropType = string | number> {
4040

4141
export type Size = "sm" | "md" | "lg";
4242

43+
export type AppearanceVariant = "outline" | "unstyled" | "flushed" | "filled";
44+
4345
export type TagVariant = "subtle" | "solid" | "outline";
4446

4547
export type SelectedOptionStyle = "color" | "check";

0 commit comments

Comments
 (0)