-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: `Center` and `Stack` atoms
- Loading branch information
Showing
8 changed files
with
242 additions
and
5 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/epo-react-lib/src/atomic/Center/Center.stories.tsx
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,67 @@ | ||
import { Meta, StoryFn, StoryObj } from "@storybook/react"; | ||
|
||
import Center from "."; | ||
import { FunctionComponent } from "react"; | ||
import Stack from "../Stack"; | ||
|
||
const meta: Meta<typeof Center> = { | ||
component: Center, | ||
argTypes: { | ||
maxWidth: { control: "text" }, | ||
andText: { control: "boolean" }, | ||
intrinsic: { control: "boolean" }, | ||
gutter: { control: "text" }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
const Iterator: FunctionComponent<{ | ||
backgroundColor?: string; | ||
iterables: Array<number | Array<number>>; | ||
}> = ({ backgroundColor = "var(--color-rubin-teal-400)", iterables }) => { | ||
return iterables.map((iteration, i) => { | ||
const hasChildren = Array.isArray(iteration); | ||
return ( | ||
<div | ||
key={i} | ||
style={ | ||
hasChildren | ||
? {} | ||
: { | ||
backgroundColor, | ||
borderRadius: "var(--size-spacing-2xs)", | ||
color: "var(--color-font-invert)", | ||
padding: "var(--size-spacing-s)", | ||
} | ||
} | ||
> | ||
{hasChildren ? ( | ||
<Iterator | ||
backgroundColor="var(--color-rubin-teal-200)" | ||
iterables={iteration} | ||
/> | ||
) : ( | ||
iteration | ||
)} | ||
</div> | ||
); | ||
}); | ||
}; | ||
|
||
const Template: StoryFn<typeof Center> = (args) => { | ||
const iterables = [1, 2, 3, 4, 5, 6]; | ||
|
||
return ( | ||
<Center {...args}> | ||
<Stack> | ||
<Iterator {...{ iterables }} /> | ||
</Stack> | ||
</Center> | ||
); | ||
}; | ||
|
||
export const Primary: StoryObj<typeof Center> = Template.bind({}); | ||
|
||
Primary.args = { | ||
maxWidth: "60ch", | ||
}; |
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,38 @@ | ||
import { FunctionComponent, PropsWithChildren } from "react"; | ||
import * as Styled from "./styles"; | ||
|
||
export interface CenterProps { | ||
/** The maximum width of the centered element */ | ||
maxWidth?: string; | ||
/** Whether to apply `text-align: center` too */ | ||
andText?: boolean; | ||
/** The width of the gutters (leave empty for no gutters) */ | ||
gutter?: string; | ||
/** Whether to center and child elements narrower than the max value */ | ||
intrinsic?: boolean; | ||
className?: string; | ||
} | ||
|
||
const Center: FunctionComponent<PropsWithChildren<CenterProps>> = ({ | ||
maxWidth = "auto", | ||
andText, | ||
gutter = "0", | ||
intrinsic, | ||
className, | ||
children, | ||
}) => { | ||
return ( | ||
<Styled.Center | ||
data-center-text={andText} | ||
data-intrinsic={intrinsic} | ||
style={{ "--size-width-center": maxWidth, "--size-gutters": gutter }} | ||
className={className} | ||
> | ||
{children} | ||
</Styled.Center> | ||
); | ||
}; | ||
|
||
Center.displayName = "Atom.Center"; | ||
|
||
export default Center; |
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,19 @@ | ||
"use client"; | ||
import styled from "styled-components"; | ||
|
||
export const Center = styled.div` | ||
box-sizing: content-box; | ||
margin-inline: auto; | ||
max-inline-size: var(--size-width-center); | ||
padding-inline: var(--size-gutters); | ||
&[data-center-text="true"] { | ||
text-align: center; | ||
} | ||
&[data-intrinsic="true"] { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
`; |
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,54 @@ | ||
import { Meta, StoryFn, StoryObj } from "@storybook/react"; | ||
|
||
import Stack from "."; | ||
import { FunctionComponent } from "react"; | ||
|
||
const meta: Meta<typeof Stack> = { | ||
component: Stack, | ||
}; | ||
export default meta; | ||
|
||
const Iterator: FunctionComponent<{ | ||
backgroundColor?: string; | ||
iterables: Array<number | Array<number>>; | ||
}> = ({ backgroundColor = "var(--color-rubin-teal-400)", iterables }) => { | ||
return iterables.map((iteration, i) => { | ||
const hasChildren = Array.isArray(iteration); | ||
return ( | ||
<div | ||
key={i} | ||
style={ | ||
hasChildren | ||
? {} | ||
: { | ||
backgroundColor, | ||
borderRadius: "var(--size-spacing-2xs)", | ||
color: "var(--color-font-invert)", | ||
padding: "var(--size-spacing-s)", | ||
} | ||
} | ||
> | ||
{hasChildren ? ( | ||
<Iterator | ||
backgroundColor="var(--color-rubin-teal-200)" | ||
iterables={iteration} | ||
/> | ||
) : ( | ||
iteration | ||
)} | ||
</div> | ||
); | ||
}); | ||
}; | ||
|
||
const Template: StoryFn<typeof Stack> = (args) => { | ||
const iterables = [1, 2, 3, [3.1, 3.2], 4, 5, 6]; | ||
|
||
return ( | ||
<Stack {...args}> | ||
<Iterator {...{ iterables }} /> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export const Primary: StoryObj<typeof Stack> = Template.bind({}); |
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,33 @@ | ||
import { FunctionComponent, PropsWithChildren } from "react"; | ||
import * as Styled from "./styles"; | ||
|
||
export interface StackProps { | ||
/** A CSS `margin` value */ | ||
space?: string; | ||
/** Whether the spaces apply recursively (i.e. regardless of nesting level) */ | ||
recursive?: boolean; | ||
className?: string; | ||
} | ||
|
||
const Stack: FunctionComponent<PropsWithChildren<StackProps>> = ({ | ||
space = "var(--size-spacing-s)", | ||
recursive = false, | ||
className, | ||
children, | ||
}) => { | ||
return ( | ||
<Styled.Stack | ||
style={{ | ||
"--size-spacing-stack": space, | ||
}} | ||
data-recursive={recursive} | ||
className={className} | ||
> | ||
{children} | ||
</Styled.Stack> | ||
); | ||
}; | ||
|
||
Stack.displayName = "Atom.Stack"; | ||
|
||
export default Stack; |
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 @@ | ||
"use client"; | ||
import styled from "styled-components"; | ||
|
||
export const Stack = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
&[data-recursive="true"] { | ||
* { | ||
margin-block: 0; | ||
} | ||
* + * { | ||
margin-block-start: var(--size-spacing-stack, 1rem); | ||
} | ||
} | ||
&[data-recursive="false"] { | ||
> * { | ||
margin-block: 0; | ||
} | ||
> * + * { | ||
margin-block-start: var(--size-spacing-stack, 1rem); | ||
} | ||
} | ||
`; |
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