Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build custom react-select component with Chakra [updated] #12065

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ce0e5ae
build(deps): bump `react-select` to v5.8.0
TylerAPfledderer Jan 30, 2024
eaad9bb
feat(ReactSelect): create components, theming and initial stories
TylerAPfledderer Jan 30, 2024
c0c8474
refactor(CentralizedExchanges): apply new `ReactSelect` component
TylerAPfledderer Jan 30, 2024
dbdf622
refactor(WalletTable): apply new `ReactSelect` component
TylerAPfledderer Jan 30, 2024
b8b7122
refactor(Layer2Onboard): implement new `ReactSelect` component
TylerAPfledderer Jan 30, 2024
e81319e
refactor(StakingLaunchpadWidget): apply new `ReactSelect` component
TylerAPfledderer Feb 2, 2024
895cc8a
style(CentralizedExchanges): add style wrapper around `ReactSelect` i…
TylerAPfledderer Feb 2, 2024
9b1d7ef
chore(Layer2Onboard): remove unused select component
TylerAPfledderer Feb 2, 2024
664ab76
refactor(Layer2Onboard): simplify check in `handleExchangeOnboard`
TylerAPfledderer Feb 2, 2024
17a6467
Merge remote-tracking branch 'origin/dev' into refactor/react-select-…
TylerAPfledderer Feb 2, 2024
56f9a0f
Merge remote-tracking branch 'origin/dev' into refactor/react-select-…
TylerAPfledderer Feb 14, 2024
e800a35
refactor(ReactSelect.stories.tsx): add story decorator
TylerAPfledderer Feb 14, 2024
c3b9c72
refactor(ReactSelect.stories.tsx): have only one story with variants
TylerAPfledderer Feb 14, 2024
a6949af
fix(theme/ReactSelect): set `overflowY` for menu list to `auto`
TylerAPfledderer Feb 14, 2024
795bfbf
style(ReactSelect): set color for group heading
TylerAPfledderer Feb 14, 2024
ec6c22c
style(ReactSelect): update styles to DS
TylerAPfledderer Feb 14, 2024
74a3349
fix(Layer2Onboard): fix vertical spacing of ReactSelect components
TylerAPfledderer Feb 14, 2024
321784a
fix(theme/ReactSelect): fix border colors for flushed variant.
TylerAPfledderer Feb 15, 2024
6547732
style(ReactSelect): split `data-focus` and `data-active` styles for t…
TylerAPfledderer Feb 15, 2024
178aec5
revert(ReactSelect): remove menu style overrides
TylerAPfledderer Feb 15, 2024
dcd8395
Merge remote-tracking branch 'upstream/dev' into refactor/react-selec…
TylerAPfledderer Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"react-i18next": "^13.3.1",
"react-icons": "^4.10.1",
"react-lite-youtube-embed": "^2.4.0",
"react-select": "^4.3.0",
"react-select": "5.8.0",
"reading-time": "^1.5.0",
"recharts": "^2.7.3",
"remark-gfm": "^3.0.1",
Expand Down Expand Up @@ -93,4 +93,4 @@
"resolutions": {
"jackspeak": "2.1.1"
}
}
}
135 changes: 135 additions & 0 deletions src/@chakra-ui/components/ReactSelect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { createMultiStyleConfigHelpers, cssVar } from "@chakra-ui/react"

import { reactSelectAnatomyKeys } from "@/components/ReactSelect/innerComponents"

const $borderBaseWidth = cssVar("border-base-width")

const { defineMultiStyleConfig, definePartsStyle } =
createMultiStyleConfigHelpers(reactSelectAnatomyKeys)

const baseStyle = definePartsStyle({
container: {
[$borderBaseWidth.variable]: "borders.1px",
w: "full",
minH: 10.5,
cursor: "pointer",
position: "relative",
zIndex: 1,
"& > .react-select__menu": {
zIndex: -1,
},
},
control: {
border: $borderBaseWidth.reference,
borderColor: "currentColor",
outlineOffset: "-2px",
p: 2,
gap: 4,
_hover: {
color: "primary.base",
borderColor: "primary.lowContrast",
},
"&[data-expanded=true]": {
bg: "background.highlight",
color: "primary.base",
borderColor: "primary.lowContrast",
},
"&:focus-within:not([data-expanded=true])": {
outline: "3px solid",
outlineColor: "primary.hover",
borderColor: "transparent",
},
},
groupHeading: {
color: "body.medium",
},
indicatorIcon: {
fontSize: "sm",
transitionProperty: "common",
transitionDuration: "normal",
"*[data-expanded=true] &": {
transform: "rotate(180deg)",
},
},
menuList: {
bg: "background.highlight",
w: "full",
maxH: "xs",
overflowY: "auto",
},
option: {
color: "body.base",
p: 2,
"&[data-focused=true]": {
bg: "primary.lowContrast",
color: "primary.base",
},
"&[data-active=true]": {
bg: "body.light",
color: "primary.visited",
},
},
})

const $borderTopRadius = cssVar("border-top-radius")

const variantFlushed = definePartsStyle({
container: {
[$borderTopRadius.variable]: "radii.base",
borderTopRadius: $borderTopRadius.reference,
},
control: {
borderTopRadius: $borderTopRadius.reference,
borderTopColor: "transparent",
borderInlineColor: "transparent",
_hover: {
borderTopColor: "transparent",
borderInlineColor: "transparent",
},
"&[data-expanded=true]": {
borderColor: "body.light",
borderBottomColor: "primary.base",
},
},
menuList: {
borderInline: $borderBaseWidth.reference,
borderBottom: $borderBaseWidth.reference,
borderColor: "body.light",
borderBottomRadius: "base",
},
})

const $borderOutlineRadius = cssVar("border-outline-radius")

const variantOutline = definePartsStyle({
container: {
[$borderOutlineRadius.variable]: "radii.base",
borderRadius: $borderOutlineRadius.reference,
},
control: {
borderRadius: $borderOutlineRadius.reference,
"&[data-expanded=true]": {
borderBottomColor: "transparent",
borderBottomRadius: "none",
},
},
menuList: {
borderInline: $borderBaseWidth.reference,
borderBottom: $borderBaseWidth.reference,
borderColor: "primary.lowContrast",
borderBottomRadius: "base",
},
})

const variants = {
flushed: variantFlushed,
outline: variantOutline,
}

export const ReactSelect = defineMultiStyleConfig({
baseStyle,
variants,
defaultProps: {
variant: "flushed",
},
})
2 changes: 2 additions & 0 deletions src/@chakra-ui/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Link } from "./Link"
import { Modal } from "./Modal"
import { Progress } from "./Progress"
import { Radio } from "./Radio"
import { ReactSelect } from "./ReactSelect"
import { Select } from "./Select"
import { Switch } from "./Switch"
import { Table } from "./Table"
Expand Down Expand Up @@ -50,6 +51,7 @@ export default {
Modal,
Progress,
Radio,
ReactSelect,
Select,
Spinner: spinnerDefaultTheme,
Switch,
Expand Down
27 changes: 13 additions & 14 deletions src/components/CentralizedExchanges/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRouter } from "next/router"
import { useTranslation } from "next-i18next"
import { Box, Center, chakra, Flex } from "@chakra-ui/react"
import { Box, Center, Flex } from "@chakra-ui/react"

import type { ChildOnlyProp, Lang } from "@/lib/types"

Expand All @@ -9,7 +9,7 @@ import Emoji from "@/components/Emoji"
import InlineLink from "@/components/Link"
import OldHeading from "@/components/OldHeading"
import Text from "@/components/OldText"
import { StyledSelect } from "@/components/SharedStyledComponents"
import ReactSelect from "@/components/ReactSelect"

import { getLocaleTimestamp } from "@/lib/utils/time"

Expand Down Expand Up @@ -50,10 +50,6 @@ const EmptyStateText = (props: ChildOnlyProp) => (
<Text m={8} fontSize="xl" maxW="450px" textAlign="center" {...props} />
)

const Select = chakra(StyledSelect, {
baseStyle: { maxW: "container.sm" },
})

const NoResults = ({ children }) => (
<EmptyStateContainer>
<Emoji text=":crying_face:" fontSize="80px" />
Expand Down Expand Up @@ -106,14 +102,17 @@ const CentralizedExchanges = ({
<Text maxW="container.sm" mb={8} lineHeight={1.4} textAlign="center">
{t("page-get-eth-exchanges-intro")}
</Text>
<Select
aria-label={t("page-get-eth-exchanges-header")}
className="react-select-container"
classNamePrefix="react-select"
options={selectOptions}
onChange={handleSelectChange as any} // TODO: Fix typing
placeholder={placeholderString}
/>
<Box w="full" maxW="container.sm">
<ReactSelect
instanceId="eth-exchange-region"
aria-label={t("page-get-eth-exchanges-header")}
options={selectOptions}
onChange={handleSelectChange}
placeholder={placeholderString}
isSearchable
variant="outline"
/>
</Box>
{!hasSelectedCountry && (
<EmptyStateContainer>
<Emoji text=":world_map:" fontSize="80px" />
Expand Down
Loading
Loading