-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create docs-ui package with LinkableHeading component (#1401)
* Initial commit * Fix start * Update package dependencies * WIP - add LinkableHeading to package * ditto * Use workspace braid * Update crackle * Remove stub component * Add VE dep * Rename package from documentation-design to docs-ui * Add README * Use original LinkableHeading component within Braid site * Add changeset * Fix package build step * Build script fix * Update readme * Write real changeset * Removing docs-ui from site until adoption PR * Add docs ui logo * Add logo to README * Icon test * Add dark mode icon and update formatting in readme * Add github light mode only tag to svg --------- Co-authored-by: Michael Taranto <[email protected]>
- Loading branch information
1 parent
680cf40
commit 56972ea
Showing
16 changed files
with
207 additions
and
2 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,13 @@ | ||
--- | ||
'@braid-design-system/docs-ui': major | ||
--- | ||
|
||
Create new package named `docs-ui`. | ||
|
||
This package will contain components for building documentation sites with a consistent user experience to the [Braid Design System] website. | ||
|
||
Currently, this package contains: | ||
* A single component: `LinkableHeading`. | ||
* A README.md for documenting this package and all its components. | ||
|
||
[Braid Design System]: https://seek-oss.github.io/braid-design-system/ |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"start": "nx run site:start", | ||
"start:playroom": "nx run site:start:playroom", | ||
"build": "nx run braid-design-system:build", | ||
"build:docs-ui": "nx run docs-ui:build", | ||
"build:site": "nx run site:build", | ||
"storybook": "nx run braid-design-system:storybook", | ||
"storybook:build": "nx run braid-design-system:storybook:build", | ||
|
@@ -24,7 +25,7 @@ | |
"deploy": "node scripts/deploy.js", | ||
"post-commit-status": "node scripts/postCommitStatus.js", | ||
"release": "pnpm prepare-publish && changeset publish && pnpm build:site && pnpm run deploy", | ||
"prepare-publish": "pnpm build && tsx scripts/copyReadme.cts", | ||
"prepare-publish": "pnpm build && pnpm build:docs-ui && tsx scripts/copyReadme.cts", | ||
"version": "changeset version && tsx scripts/versionComponentUpdates.cts && pnpm install --lockfile-only", | ||
"changeset": "EDITOR=scripts/writeBraidFrontMatter.js ./node_modules/.bin/changeset add --open" | ||
}, | ||
|
@@ -85,6 +86,7 @@ | |
"packageManager": "[email protected]", | ||
"pnpm": { | ||
"overrides": { | ||
"@braid-design-system/docs-ui": "workspace:*", | ||
"@braid-design-system/generate-component-docs": "workspace:*", | ||
"@braid-design-system/source.macro": "workspace:*", | ||
"braid-design-system": "workspace:*" | ||
|
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,3 @@ | ||
# managed by crackle | ||
/dist | ||
# end managed by crackle |
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,39 @@ | ||
<img src="https://raw.githubusercontent.com/seek-oss/braid-design-system/HEAD/packages/docs-ui/images/braid-docs-ui-logo.svg#gh-light-mode-only" alt="Braid Docs UI" title="Braid Docs UI" width="80px"> | ||
<img src="https://raw.githubusercontent.com/seek-oss/braid-design-system/HEAD/packages/docs-ui/images/braid-docs-ui-logo-inverted.svg#gh-dark-mode-only" alt="Braid Docs UI" title="Braid Docs UI" width="80px" /> | ||
<br/> | ||
|
||
# docs-ui | ||
|
||
Components for building documentation sites with a consistent user experience to the [Braid Design System] website. | ||
|
||
```bash | ||
npm install @braid-design-system/docs-ui | ||
``` | ||
|
||
- [LinkableHeading](#linkableheading) | ||
|
||
## Usage | ||
|
||
### `LinkableHeading` | ||
|
||
A heading wrapped in a link to a hash that is generated based on the heading content, enabling deep links within documentation pages. | ||
|
||
#### Example | ||
|
||
```tsx | ||
import { LinkableHeading } from '@braid-design-system/docs-ui'; | ||
|
||
<LinkableHeading>Section heading</LinkableHeading>; | ||
``` | ||
|
||
#### Props | ||
|
||
| props | value | description | | ||
| --------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| level | [`HeadingLevel`] | The heading size (defaults to `3`) | | ||
| component | `string` | HTML element to render, e.g. “h1”, “h2”, etc. | | ||
| children | `string` | Visible heading content, converted to slug (e.g. “section-heading”) to be used as hash link.<br/>Note: If the heading | | ||
| label | `string` | Override the slug used as the hash link.<br/><br/>_Note: If the content of the heading is more than a simple string that can be slugified, then the `label` is required._ | | ||
|
||
[`HeadingLevel`]: https://seek-oss.github.io/braid-design-system/components/Heading | ||
[Braid Design System]: https://seek-oss.github.io/braid-design-system/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,40 @@ | ||
{ | ||
"name": "@braid-design-system/docs-ui", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"author": "SEEK", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"dev": "crackle dev --webpack", | ||
"build": "crackle package", | ||
"format:eslint": "eslint --cache --fix .", | ||
"format:prettier": "prettier --cache --write .", | ||
"lint:eslint": "eslint --cache .", | ||
"lint:prettier": "prettier --cache --list-different .", | ||
"lint:tsc": "tsc" | ||
}, | ||
"dependencies": { | ||
"@vanilla-extract/css": "^1.9.2" | ||
}, | ||
"devDependencies": { | ||
"braid-design-system": "*", | ||
"react": "^18.2.0" | ||
}, | ||
"peerDependencies": { | ||
"braid-design-system": "^32.0.0", | ||
"react": "^18.2.0" | ||
} | ||
} |
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,16 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/nrwl/nx/15.6.3/packages/nx/schemas/project-schema.json", | ||
"namedInputs": { | ||
"default": ["{projectRoot}/**/*"] | ||
}, | ||
"targets": { | ||
"build": { | ||
"executor": "nx:run-script", | ||
"options": { | ||
"script": "build" | ||
} | ||
}, | ||
"lint": {}, | ||
"format": {} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/docs-ui/src/components/LinkableHeading/LinkableHeading.css.ts
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,10 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const linkableHeading = style({}); | ||
export const hashLink = style({ | ||
selectors: { | ||
[`${linkableHeading}:hover &`]: { | ||
opacity: 1, | ||
}, | ||
}, | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/docs-ui/src/components/LinkableHeading/LinkableHeading.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,48 @@ | ||
import React, { type ReactNode, type ComponentProps } from 'react'; | ||
import { Heading, Box, IconLink, Link } from 'braid-design-system'; | ||
import * as styles from './LinkableHeading.css'; | ||
|
||
type HeadingProps = ComponentProps<typeof Heading>; | ||
|
||
type LinkableHeadingProps = { | ||
level?: HeadingProps['level']; | ||
component?: HeadingProps['component']; | ||
} & ({ children: string } | { children: ReactNode; label: string }); | ||
|
||
const slugify = (string: string) => | ||
string | ||
.replace(/[\s?]/g, '-') | ||
.replace('--', '-') | ||
.replace(/-$/, '') | ||
.toLowerCase(); | ||
|
||
export const LinkableHeading = ({ | ||
level = '3', | ||
component, | ||
...restProps | ||
}: LinkableHeadingProps) => { | ||
const label = 'label' in restProps ? restProps.label : restProps.children; | ||
const slug = slugify(label); | ||
|
||
return ( | ||
<Box display="flex"> | ||
<Box className={styles.linkableHeading} display="inlineBlock"> | ||
<Box id={slug} position="absolute" /> | ||
<Link href={`#${slug}`}> | ||
<Heading level={level} component={component}> | ||
{restProps.children}{' '} | ||
<Box | ||
component="span" | ||
transition="fast" | ||
marginLeft="xxsmall" | ||
opacity={0} | ||
className={styles.hashLink} | ||
> | ||
<IconLink /> | ||
</Box> | ||
</Heading> | ||
</Link> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
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 @@ | ||
export { LinkableHeading } from './components/LinkableHeading/LinkableHeading'; |
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,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["./src"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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