-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(seed-docs): color foundation palette
- Loading branch information
1 parent
dacea16
commit ac3084e
Showing
6 changed files
with
670 additions
and
94 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
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 |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import clsx from "clsx"; | ||
import type { HTMLAttributes } from "react"; | ||
|
||
import * as style from "./Table.css"; | ||
|
||
export const Table = (props: Object) => ( | ||
<div className={style.tableWrapper}> | ||
<table className={clsx(style.table)} {...props}></table> | ||
</div> | ||
); | ||
export const Table = (props: HTMLAttributes<HTMLTableElement>) => { | ||
const { className, ...rest } = props; | ||
return ( | ||
<div className={style.tableWrapper}> | ||
<table className={clsx(style.table, className)} {...rest}></table> | ||
</div> | ||
); | ||
}; | ||
|
||
export const TableHead = (props: Object) => ( | ||
<thead className={clsx(style.tableHead)} {...props}></thead> | ||
); | ||
export const TableHead = (props: HTMLAttributes<HTMLTableSectionElement>) => { | ||
const { className, ...rest } = props; | ||
return <thead className={clsx(style.tableHead, className)} {...rest}></thead>; | ||
}; | ||
|
||
export const TableBody = (props: Object) => ( | ||
<tbody className={clsx(style.tableBody)} {...props}></tbody> | ||
); | ||
export const TableBody = (props: HTMLAttributes<HTMLTableSectionElement>) => { | ||
const { className, ...rest } = props; | ||
return <tbody className={clsx(style.tableBody, className)} {...rest}></tbody>; | ||
}; | ||
|
||
export const TableRow = (props: Object) => ( | ||
<tr className={clsx(style.tableRow)} {...props}></tr> | ||
); | ||
export const TableRow = (props: HTMLAttributes<HTMLTableRowElement>) => { | ||
const { className, ...rest } = props; | ||
return <tr className={clsx(style.tableRow, className)} {...rest}></tr>; | ||
}; | ||
|
||
export const TableData = (props: Object) => ( | ||
<td className={clsx(style.tableData)} {...props}></td> | ||
); | ||
export const TableData = (props: HTMLAttributes<HTMLTableCellElement>) => { | ||
const { className, ...rest } = props; | ||
return <td className={clsx(style.tableData, className)} {...rest}></td>; | ||
}; |
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,49 @@ | ||
import React, { createContext, useContext, useState } from "react"; | ||
|
||
interface ColorPaletteProps { | ||
computedStyle: CSSStyleDeclaration | undefined; | ||
hash: string; | ||
} | ||
|
||
const ColorPaletteContext = createContext<ColorPaletteProps | null>(null); | ||
|
||
export function ColorPaletteProvider({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const [computedStyle, setComputedStyle] = useState<CSSStyleDeclaration>(); | ||
const [hash, setHash] = useState<string>(""); | ||
|
||
React.useEffect(() => { | ||
if (typeof window === "undefined") return; | ||
const style = window.getComputedStyle(document.body); | ||
setComputedStyle(style); | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
if (typeof window === "undefined") return; | ||
|
||
const handleRouteChange = () => { | ||
const url = new URL(window.location.href); | ||
setHash(url.hash.slice(1)); | ||
}; | ||
|
||
window.addEventListener("hashchange", handleRouteChange); | ||
return () => { | ||
window.removeEventListener("hashchange", handleRouteChange); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<ColorPaletteContext.Provider value={{ computedStyle, hash }}> | ||
{children} | ||
</ColorPaletteContext.Provider> | ||
); | ||
} | ||
|
||
export const useColorPaletteState = () => { | ||
const state = useContext(ColorPaletteContext); | ||
if (!state) throw new Error("Cannot find ColorPaletteContext Provider"); | ||
return state; | ||
}; |
Oops, something went wrong.