Skip to content

Commit 0c5122e

Browse files
docs: explain theme customization more (#9)
1 parent 754abe1 commit 0c5122e

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

src/components/Button/ActionButton.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ const EDGES = enumValues<NonNullable<ActionButtonProps["edge"]>>({
4141
none: true,
4242
})
4343

44+
/**
45+
* A button that should contain a remixicon icon and nothing else.
46+
*/
4447
const meta: Meta<typeof ActionButton> = {
4548
title: "smoot-design/ActionButton",
4649
component: ActionButton,
@@ -166,6 +169,13 @@ export const Showcase: Story = {
166169
),
167170
}
168171

172+
/**
173+
* `ActionButtonLink` is styled as a `ActionButton` that renders an anchor tag.
174+
*
175+
* To use a custom link component (E.g. `Link` from `react-router` or `next/link`),
176+
* pass it as the `Component` prop. Alternatively, customize the project-wide
177+
* default link adapter via [Theme's LinkAdapter](../?path=/docs/smoot-design-themeprovider--docs)
178+
*/
169179
export const Links: Story = {
170180
render: () => (
171181
<Stack direction="row" gap={2} sx={{ my: 2 }}>

src/components/Button/Button.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ const ButtonInner: React.FC<
315315
type ButtonProps = ButtonStyleProps & React.ComponentProps<"button">
316316

317317
/**
318-
* Our standard button component.
318+
* Our standard button component. See [Button Docs](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-button--docs).
319319
*
320320
* See also:
321-
* - ButtonLink
322-
* - ActionButton
321+
* - [ButtonLink](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-button--docs#links)
322+
* - [ActionButton](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-actionbutton--docs) for icon-only uses
323323
*/
324324
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
325325
({ children, ...props }, ref) => {
@@ -336,6 +336,9 @@ type ButtonLinkProps = ButtonStyleProps &
336336
Component?: React.ElementType
337337
} & LinkAdapterPropsOverrides
338338

339+
/**
340+
* See [ButtonLink docs](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-button--docs#links)
341+
*/
339342
const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
340343
({ children, Component, ...props }: ButtonLinkProps, ref) => {
341344
return (
@@ -381,7 +384,11 @@ const actionStyles = (size: ButtonSize) => {
381384

382385
/**
383386
* A button that should contain a remixicon icon and nothing else.
384-
* For a variant that functions as a link, see ActionButtonLink.
387+
* See [ActionButton docs](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-actionbutton--docs).
388+
*
389+
* See also:
390+
* - [ActionButtonLink](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-button--docs#links)
391+
* - [Button](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-button--docs) for text buttons
385392
*/
386393
const ActionButton = styled(
387394
React.forwardRef<HTMLButtonElement, ActionButtonProps>((props, ref) => (
@@ -401,6 +408,9 @@ type ActionButtonLinkProps = ActionButtonStyleProps &
401408
Component?: React.ElementType
402409
} & LinkAdapterPropsOverrides
403410

411+
/**
412+
* See [ActionButtonLink docs](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-actionbutton--docs#links)
413+
*/
404414
const ActionButtonLink = ActionButton.withComponent(
405415
({ Component, ...props }: ButtonLinkProps) => {
406416
return <LinkStyled Component={Component} {...props} />

src/components/ThemeProvider/ThemeProvider.stories.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,44 @@ type Story = StoryObj<typeof ThemeProvider>
5151
*
5252
* In general, most useful theme properties are exposed on `theme.custom`. (Root
5353
* `theme` properties are used internally by MUI.) See typescript definitions
54-
* for more information.
54+
* for more information about `theme.custom`.
55+
*
56+
* ## Further Customized Theme with `createTheme`
57+
* Consuming applications can customize `smoot-design`'s default theme by creating
58+
* a theme instance with `createTheme` and passing it to `ThemeProvider`:
59+
*
60+
* ```tsx
61+
* const customTheme = createTheme({...})
62+
*
63+
* <ThemeProvider theme={customTheme}>
64+
* {children}
65+
* </ThemeProvider>
66+
* ```
67+
*
5568
*
5669
* ### Custom Link Adapter
5770
* One particularly notable property is `theme.custom.LinkAdapter`. Some `smoot-design`
5871
* components render links. These links are native anchor tags by default. In
5972
* order to use these components with custom routing libraries (e.g. `react-router`
60-
* or `next/link`), you can provide a custom link adapter. Link components wills
73+
* or `next/link`), you can provide a custom link adapter.
6174
*
62-
* As an example, `ButtonLink` will:
75+
* Components such as `ButtonLink` will:
6376
* - use `Component` on `ButtonLink` if specified (`<ButtonLink Component={Link} />`)
6477
* - else, use `theme.custom.LinkAdapter` if specified,
6578
* - else, use `a` tag.
6679
*
67-
* If you provide a custom `LinkAdapter` and need **aditional** props, you can
68-
* use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) to add the custom props to relevant
69-
* components. For example, if using `next/link`
80+
* For example, to use `next/link` as the default link implementation:
81+
*
82+
* ```tsx
83+
* import Link from "next/link"
84+
* const theme = createTheme({ LinkAdapter: Link })
7085
* ```
86+
*
87+
* You can use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)
88+
* to add the custom props to relevant components. For example, to expose
89+
* `next/link`'s `scroll` prop on `ButtonLink`:
90+
*
91+
* ```ts
7192
* // Add scroll prop to all components using LinkAdapter
7293
* declare module "@mitodl/smoot-design" {
7394
* interface LinkAdapterPropsOverrides {

src/components/ThemeProvider/ThemeProvider.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ type ExtendedTheme = Theme & {
9898
custom: CustomTheme
9999
}
100100

101+
/**
102+
* Create a customized Smoot Design theme for use with `ThemeProvider`.
103+
*
104+
* See [ThemeProvider Docs](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-themeprovider--docs#further-customized-theme-with-createtheme)
105+
* for more.
106+
*/
101107
const createTheme = (options?: {
102108
custom: Partial<ThemeOptions["custom"]>
103109
}): ExtendedTheme =>
@@ -116,6 +122,11 @@ type ThemeProviderProps = {
116122
theme?: Theme
117123
}
118124

125+
/**
126+
*
127+
* @param param0
128+
* @returns
129+
*/
119130
const ThemeProvider: React.FC<ThemeProviderProps> = ({
120131
children,
121132
theme = defaultTheme,

0 commit comments

Comments
 (0)