Skip to content

Commit 4e3ed54

Browse files
feat: new uikit of MultiSelect (#10103) (#10104)
<!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR adds MultiSelect components to the UI kit and internal widgets. It also introduces a SearchBox component for filtering. ### Detailed summary - Added MultiSelect components to UI kit and internal widgets - Introduced SearchBox component for filtering - Updated Checkbox component styles - Added Select and MultiSelect stories for documentation > The following files were skipped due to too many changes: `packages/uikit/src/components/MultiSelect/SearchBox.tsx`, `packages/uikit/src/components/MultiSelect/MultiSelect.tsx`, `pnpm-lock.yaml` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR adds a `MultiSelect` component and updates the `Checkbox` type. ### Detailed summary - Added `MultiSelect` component - Updated `Checkbox` type to accept string in `scale` - Added `primereact` dependency - Updated storybook for `Select` and `MultiSelect` - Implemented `MultiSelect` component with styling and functionality > The following files were skipped due to too many changes: `pnpm-lock.yaml` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --------- Co-authored-by: chefjackson <[email protected]>
1 parent c6300d3 commit 4e3ed54

File tree

18 files changed

+740
-34
lines changed

18 files changed

+740
-34
lines changed

Diff for: .changeset/flat-seahorses-visit.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@pancakeswap/uikit': minor
3+
---
4+
5+
Add MultiSelect Component

Diff for: packages/uikit/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
"framer-motion": "10.16.4",
134134
"lightweight-charts": "^4.0.1",
135135
"lodash": "^4.17.20",
136+
"primereact": "^10.6.6",
136137
"react-popper": "^2.3.0",
137138
"sonner": "^1.2.4",
138139
"styled-system": "^5.1.5",

Diff for: packages/uikit/src/__tests__/components/checkbox.test.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ it("renders correctly", () => {
2626
box-shadow: var(--shadows-inset);
2727
}
2828
29+
.c0:before {
30+
content: "";
31+
position: absolute;
32+
border-top: 2px solid;
33+
border-color: transparent;
34+
top: 50%;
35+
left: 50%;
36+
width: 33%;
37+
height: 0;
38+
margin: auto;
39+
transform: translate(-50%, -50%);
40+
transition: border-color 0.2s ease-in-out;
41+
}
42+
2943
.c0:after {
3044
content: "";
3145
position: absolute;

Diff for: packages/uikit/src/components/Checkbox/Checkbox.tsx

+44-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { styled } from "styled-components";
2-
import { CheckboxProps, scales } from "./types";
2+
import { CheckboxProps, Scales, scales } from "./types";
33

44
const getScale = ({ scale }: CheckboxProps) => {
5-
switch (scale) {
6-
case scales.XS:
7-
return "20px";
8-
case scales.SM:
9-
return "24px";
10-
case scales.MD:
11-
default:
12-
return "32px";
5+
if (scale && Object.values(scales).includes(scale as Scales)) {
6+
switch (scale) {
7+
case scales.XS:
8+
return "20px";
9+
case scales.SM:
10+
return "24px";
11+
case scales.MD:
12+
default:
13+
return "32px";
14+
}
1315
}
16+
return scale;
1417
};
1518

1619
const Checkbox = styled.input.attrs({ type: "checkbox" })<CheckboxProps>`
@@ -25,11 +28,30 @@ const Checkbox = styled.input.attrs({ type: "checkbox" })<CheckboxProps>`
2528
min-width: ${getScale};
2629
vertical-align: middle;
2730
transition: background-color 0.2s ease-in-out;
28-
border: ${({ theme }) => (theme.isDark ? `solid 1px ${theme.colors.disabled}` : "0")};
31+
border: ${({ theme, colors }) =>
32+
colors?.border
33+
? `solid 1px ${theme.colors[colors.border]}`
34+
: theme.isDark
35+
? `solid 1px ${theme.colors.disabled}`
36+
: "0"};
2937
border-radius: 8px;
30-
background-color: ${({ theme }) => theme.colors.cardBorder};
38+
background-color: ${({ theme, colors }) => theme.colors[colors?.background ?? "cardBorder"]};
3139
box-shadow: ${({ theme }) => theme.shadows.inset};
3240
41+
&:before {
42+
content: "";
43+
position: absolute;
44+
border-top: 2px solid;
45+
border-color: transparent;
46+
top: 50%;
47+
left: 50%;
48+
width: 33%;
49+
height: 0;
50+
margin: auto;
51+
transform: translate(-50%, -50%);
52+
transition: border-color 0.2s ease-in-out;
53+
}
54+
3355
&:after {
3456
content: "";
3557
position: absolute;
@@ -46,6 +68,16 @@ const Checkbox = styled.input.attrs({ type: "checkbox" })<CheckboxProps>`
4668
transition: border-color 0.2s ease-in-out;
4769
}
4870
71+
${({ indeterminate, theme, colors }) =>
72+
indeterminate &&
73+
`
74+
border: 0;
75+
background-color: ${theme.colors[colors?.checkedBackground ?? "success"]};
76+
&:before {
77+
border-color: white;
78+
}
79+
`}
80+
4981
&:hover:not(:disabled):not(:checked) {
5082
box-shadow: ${({ theme }) => theme.shadows.focus};
5183
}
@@ -57,7 +89,7 @@ const Checkbox = styled.input.attrs({ type: "checkbox" })<CheckboxProps>`
5789
5890
&:checked {
5991
border: 0;
60-
background-color: ${({ theme }) => theme.colors.success};
92+
background-color: ${({ theme, colors }) => theme.colors[colors?.checkedBackground ?? "success"]};
6193
&:after {
6294
border-color: white;
6395
}

Diff for: packages/uikit/src/components/Checkbox/types.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PancakeTheme } from "../../theme";
2+
13
export const scales = {
24
XS: "xs",
35
SM: "sm",
@@ -7,5 +9,11 @@ export const scales = {
79
export type Scales = (typeof scales)[keyof typeof scales];
810

911
export interface CheckboxProps {
10-
scale?: Scales;
12+
scale?: Scales | string;
13+
colors?: {
14+
background?: keyof PancakeTheme["colors"];
15+
checkedBackground?: keyof PancakeTheme["colors"];
16+
border?: keyof PancakeTheme["colors"];
17+
};
18+
indeterminate?: boolean;
1119
}

0 commit comments

Comments
 (0)