-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement the divider the correct way * Add changeset
- Loading branch information
Showing
4 changed files
with
66 additions
and
14 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 @@ | ||
--- | ||
"@vygruppen/spor-react": minor | ||
--- | ||
|
||
Divider: Implement size and variant props |
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
import { As, Box, BoxProps, forwardRef } from "@chakra-ui/react"; | ||
import { | ||
As, | ||
BoxProps, | ||
Divider as ChakraDivider, | ||
DividerProps as ChakraDividerProps, | ||
forwardRef, | ||
} from "@chakra-ui/react"; | ||
import React from "react"; | ||
|
||
export type DividerProps = BoxProps; | ||
export type DividerProps = ChakraDividerProps & { | ||
size?: "sm" | "md" | "lg"; | ||
variant?: "solid" | "dashed"; | ||
}; | ||
/** A dividing line, used to divide content. | ||
* | ||
* You can specify margins if you need to give the content some space, or use a `Stack` component to do it for you | ||
* | ||
* ```tsx | ||
* <Divider marginTop={4} marginBottom={6} /> | ||
* ``` | ||
* | ||
* There are three different sizes available: `sm`, `md` and `lg`. The default is `md`. | ||
* There are two different variants available: `solid` and `dashed`. The default is `solid`. | ||
*/ | ||
export const Divider = forwardRef<BoxProps, As>((props, ref) => { | ||
return ( | ||
<Box | ||
as="hr" | ||
height="2px" | ||
border="0" | ||
borderRadius="1px" | ||
backgroundColor="blackAlpha.200" | ||
width="100%" | ||
{...props} | ||
ref={ref} | ||
/> | ||
); | ||
return <ChakraDivider {...props} ref={ref} />; | ||
}); |
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,44 @@ | ||
import { defineStyle, defineStyleConfig } from "@chakra-ui/styled-system" | ||
import { mode } from "@chakra-ui/theme-tools" | ||
|
||
const baseStyle = defineStyle(props => ({ | ||
borderColor: mode("blackAlpha.300", "whiteAlpha.300")(props) | ||
})) | ||
|
||
const variantSolid = defineStyle({ | ||
borderStyle: "solid", | ||
}) | ||
|
||
const variantDashed = defineStyle({ | ||
borderStyle: "dashed", | ||
}) | ||
|
||
const variants = { | ||
solid: variantSolid, | ||
dashed: variantDashed, | ||
} | ||
|
||
const sizes = { | ||
sm: { | ||
borderWidth: '1px', | ||
borderRadius: '0.5px', | ||
}, | ||
md: { | ||
borderWidth: '2px', | ||
borderRadius: '1px', | ||
}, | ||
lg: { | ||
borderWidth: '3px', | ||
borderRadius: '1.5px', | ||
}, | ||
} | ||
|
||
export default defineStyleConfig({ | ||
baseStyle, | ||
variants, | ||
sizes, | ||
defaultProps: { | ||
variant: "solid", | ||
size: 'md', | ||
}, | ||
}) |
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