-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement refund add modal * Add changeset * Add translations * Refactor & tests * Remove package.json comment * Better handling of empty state * Remove radix from package.json * Rename getHoverState * Export indicator to separate component * Handle empty state * Make RadioTiles compound component * Add translation * Handle empty state with datagrid
- Loading branch information
Showing
19 changed files
with
471 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": minor | ||
--- | ||
|
||
Implement refund add modal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as RadixRadioGroup from "@radix-ui/react-radio-group"; | ||
import { render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import { RadioTile } from "./RadioTile"; | ||
|
||
describe("RadioTile", () => { | ||
it("renders the title and description", () => { | ||
// Arrange | ||
const props = { | ||
checked: false, | ||
title: "Test Title", | ||
description: "Test Description", | ||
value: "test", | ||
}; | ||
|
||
// Act | ||
render( | ||
<RadixRadioGroup.Root> | ||
<RadioTile {...props} /> | ||
</RadixRadioGroup.Root>, | ||
); | ||
|
||
// Assert | ||
expect(screen.getByText(props.title)).toBeInTheDocument(); | ||
expect(screen.getByText(props.description)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as RadixRadioGroup from "@radix-ui/react-radio-group"; | ||
import { Box, Text } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
|
||
import { RadioTileIndicator } from "./RadioTileIndicator"; | ||
import { getBgColor, getBorderColor, getHoverStateBgColor } from "./utils"; | ||
|
||
export interface RadioTileProps { | ||
checked: boolean; | ||
title: string; | ||
description: string; | ||
value: string; | ||
} | ||
|
||
export const RadioTile = ({ | ||
checked, | ||
title, | ||
description, | ||
value, | ||
}: RadioTileProps) => { | ||
const [isHoverState, setHoverState] = React.useState(false); | ||
|
||
return ( | ||
<RadixRadioGroup.Item value={value} asChild> | ||
<Box | ||
position="relative" | ||
as="label" | ||
gap={2} | ||
display="grid" | ||
__gridTemplateColumns="auto 1fr" | ||
alignItems="center" | ||
borderColor={getBorderColor({ checked, isHoverState })} | ||
borderWidth={1} | ||
borderStyle="solid" | ||
borderRadius={2} | ||
padding={3} | ||
cursor="pointer" | ||
onMouseEnter={() => setHoverState(true)} | ||
onMouseLeave={() => setHoverState(false)} | ||
> | ||
<Box | ||
width={5} | ||
height={5} | ||
borderRadius="100%" | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
backgroundColor={getHoverStateBgColor({ checked, isHoverState })} | ||
> | ||
<Box | ||
width={3} | ||
height={3} | ||
boxShadow={checked || isHoverState ? "none" : "defaultFocused"} | ||
borderColor="default1" | ||
borderWidth={1} | ||
borderStyle={checked ? "none" : "solid"} | ||
borderRadius="100%" | ||
padding={0} | ||
backgroundColor={getBgColor({ checked, isHoverState })} | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
> | ||
<RadioTileIndicator /> | ||
</Box> | ||
</Box> | ||
<Text size={5}>{title}</Text> | ||
<Box /> | ||
<Text size={1} color="default2"> | ||
{description} | ||
</Text> | ||
</Box> | ||
</RadixRadioGroup.Item> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as RadixRadioGroup from "@radix-ui/react-radio-group"; | ||
import { sprinkles } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
|
||
export const RadioTileIndicator = () => { | ||
return ( | ||
<RadixRadioGroup.Indicator | ||
className={sprinkles({ | ||
position: "relative", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
color: "buttonDefaultPrimary", | ||
height: "100%", | ||
width: "100%", | ||
borderRadius: "100%", | ||
})} | ||
> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="6" height="6" fill="white"> | ||
<circle cx="3" cy="3" r="3" fill="currentColor" /> | ||
</svg> | ||
</RadixRadioGroup.Indicator> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as RadixRadioGroup from "@radix-ui/react-radio-group"; | ||
import React from "react"; | ||
|
||
import { RadioTile } from "./RadioTile"; | ||
|
||
export interface RadioTilesProps { | ||
children: React.ReactNode; | ||
asChild: boolean; | ||
value: string; | ||
onValueChange: (value: string) => void; | ||
} | ||
|
||
const RadioTilesBase = ({ | ||
children, | ||
asChild, | ||
value, | ||
onValueChange, | ||
}: RadioTilesProps) => { | ||
return ( | ||
<RadixRadioGroup.Root | ||
asChild={asChild} | ||
value={value} | ||
onValueChange={onValueChange} | ||
> | ||
{children} | ||
</RadixRadioGroup.Root> | ||
); | ||
}; | ||
|
||
export const RadioTiles = Object.assign(RadioTilesBase, { RadioTile }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
interface RadioTileState { | ||
checked: boolean; | ||
isHoverState: boolean; | ||
} | ||
|
||
export const getHoverStateBgColor = ({ | ||
checked, | ||
isHoverState, | ||
}: RadioTileState) => { | ||
if (checked && isHoverState) { | ||
return "accent1Hovered"; | ||
} | ||
if (isHoverState) { | ||
return "default1Hovered"; | ||
} | ||
return "transparent"; | ||
}; | ||
|
||
export const getBorderColor = ({ checked, isHoverState }: RadioTileState) => { | ||
if (checked) { | ||
return "accent1"; | ||
} | ||
if (isHoverState) { | ||
return "default1Hovered"; | ||
} | ||
return "default1"; | ||
}; | ||
|
||
export const getBgColor = ({ checked, isHoverState }: RadioTileState) => { | ||
if (checked) { | ||
return "accent1"; | ||
} | ||
if (isHoverState) { | ||
return "default1Hovered"; | ||
} | ||
return "transparent"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.