Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft][docs] Sandpack Demo #7015

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@
"karma": "^6.4.2",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-test-renderer": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "~5.3.3",
"webpack-cli": "^5.1.4"
},
Expand Down
33 changes: 19 additions & 14 deletions packages/core/src/components/button/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ using the `<Button>` and `<AnchorButton>` components, respectively.

@reactExample ButtonsExample

@## Sandpack Example

@reactExample SandpackButtonsExample

@## AnchorButton vs Button

The two button components generate different HTML tags. They each look the same, but they have different semantic
Expand All @@ -15,7 +19,7 @@ behaviors according to the HTML spec.
```

```html
<a class="@ns-button" role="button" tabindex={0}>Click</a>
<a class="@ns-button" role="button" tabindex="{0}">Click</a>
```

---
Expand All @@ -31,20 +35,21 @@ behaviors according to the HTML spec.
<div class="@ns-callout @ns-intent-danger @ns-icon-error @ns-callout-has-body-content">
<h5 class="@ns-heading">

Disabled __Button__ elements prevent all interaction
Disabled **Button** elements prevent all interaction

</h5>

Use __AnchorButton__ if you need mouse interaction events (such as hovering) on a disabled button.
Use **AnchorButton** if you need mouse interaction events (such as hovering) on a disabled button.

__Button__ uses the native `disabled` attribute on the `<button>` tag so the browser disables all interactions.
__AnchorButton__ uses the class `.@ns-disabled` because `<a>` tags do not support the `disabled` attribute. As a result,
the __AnchorButton__ component will prevent *only* the `onClick` handler when disabled but permit other events.
**Button** uses the native `disabled` attribute on the `<button>` tag so the browser disables all interactions.
**AnchorButton** uses the class `.@ns-disabled` because `<a>` tags do not support the `disabled` attribute. As a result,
the **AnchorButton** component will prevent _only_ the `onClick` handler when disabled but permit other events.

</div>

@## Adding icons

__Button__ and __AnchorButton__ support `icon` and `rightIcon` props to place an icon on either end of their text/children.
**Button** and **AnchorButton** support `icon` and `rightIcon` props to place an icon on either end of their text/children.
These icons can either be specified as string identifiers (e.g. `"arrow-right"`), dynamically-loaded
[`<Icon>` components](https://blueprintjs.com/docs/#core/components/icon),
[static icon components](#core/components/icon.static-components) (e.g. `<ArrowRight />`), or any custom JSX element.
Expand Down Expand Up @@ -76,12 +81,12 @@ often fall out of sync as the design system is updated. You should use the React
Use the `@ns-button` class to access button styles. You should implement buttons using the
`<button>` or `<a>` tags rather than `<div>` for accessibility.

* Make sure to include `type="button"` on `<button>` tags (use `type="submit"` to submit a
`<form>`) and `role="button"` on `<a>` tags for accessibility.
* Add the attribute `tabindex="0"` to make `<a>` tags focusable. `<button>` elements are
focusable by default.
* For buttons implemented with `<a>` tags, add `tabindex="-1"` to disabled buttons to prevent the
user from focusing them by pressing <kbd>tab</kbd> on the keyboard. (This does not happen in the example below.)
* Note that `<a>` tags do not respond to the `:disabled` attribute; use `.@ns-disabled` instead.
- Make sure to include `type="button"` on `<button>` tags (use `type="submit"` to submit a
`<form>`) and `role="button"` on `<a>` tags for accessibility.
- Add the attribute `tabindex="0"` to make `<a>` tags focusable. `<button>` elements are
focusable by default.
- For buttons implemented with `<a>` tags, add `tabindex="-1"` to disabled buttons to prevent the
user from focusing them by pressing <kbd>tab</kbd> on the keyboard. (This does not happen in the example below.)
- Note that `<a>` tags do not respond to the `:disabled` attribute; use `.@ns-disabled` instead.

@css button
4 changes: 2 additions & 2 deletions packages/datetime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"karma": "^6.4.2",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-test-renderer": "^16.14.0",
"typescript": "~5.3.3",
"webpack-cli": "^5.1.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/datetime2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"karma": "^6.4.2",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "~5.3.3",
"webpack-cli": "^5.1.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"classnames": "^2.3.1",
"lodash": "^4.17.21",
"normalize.css": "^8.0.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-transition-group": "^4.4.5",
"tslib": "~2.6.2"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/docs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@blueprintjs/select": "workspace:^",
"@blueprintjs/table": "workspace:^",
"@blueprintjs/test-commons": "workspace:^",
"@codesandbox/sandpack-react": "^2.19.9",
"@documentalist/client": "^5.0.0",
"chroma-js": "^2.4.2",
"classnames": "^2.3.1",
Expand All @@ -38,8 +39,8 @@
"monaco-editor": "^0.45.0",
"normalize.css": "^8.0.1",
"popper.js": "^1.16.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-transition-group": "^4.4.5",
"tslib": "~2.6.2"
},
Expand All @@ -49,6 +50,8 @@
"@types/chroma-js": "~2.4.3",
"@types/downloadjs": "~1.4.6",
"@types/lodash": "~4.14.202",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"copy-webpack-plugin": "^12.0.2",
"monaco-editor-webpack-plugin": "^7.1.0",
"npm-run-all": "^4.1.5",
Expand Down
1 change: 1 addition & 0 deletions packages/docs-app/src/examples/core-examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
export * from "./alertExample";
export * from "./breadcrumbsExample";
export * from "./buttonsExample";
export * from "./sandpackButtonsExample";
export * from "./buttonsIconsExample";
export * from "./buttonGroupExample";
export * from "./buttonGroupPopoverExample";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* !
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*/

import {
SandpackCodeEditor,
SandpackLayout,
SandpackPreview,
SandpackProvider,
type SandpackTheme,
} from "@codesandbox/sandpack-react";
import * as React from "react";

import { Colors } from "@blueprintjs/core";

const app = `import { Button } from '@blueprintjs/core'

export default function App() {
return (
<Button intent="primary">
Hello World
</Button>
);
}`;

const index = `import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { FocusStyleManager } from "@blueprintjs/core";
import "./styles.css";

import App from "./App";
import React from "react";

import "@blueprintjs/core/lib/css/blueprint.css";

FocusStyleManager.onlyShowFocusOnTabs();

const root = createRoot(document.getElementById("root") as HTMLElement);
root.render(
<StrictMode>
<App />
</StrictMode>
);
`;

const styles = `body {
background-color: #1C2127;
}
`;

const theme: SandpackTheme = {
colors: {
accent: Colors.BLUE5,
base: Colors.GRAY3,
clickable: Colors.GRAY2,
disabled: Colors.DARK_GRAY4,
error: Colors.RED5,
errorSurface: Colors.RED1,
hover: Colors.GRAY5,
surface1: Colors.BLACK,
surface2: Colors.DARK_GRAY2,
surface3: Colors.DARK_GRAY5,
},
font: {
body: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", blueprint-icons-16, sans-serif',
lineHeight: "20px",
mono: '"Fira Mono", "DejaVu Sans Mono", Menlo, Consolas, "Liberation Mono", Monaco, "Lucida Console", monospace',
size: "13px",
},
syntax: {
comment: { color: Colors.GRAY2, fontStyle: "italic" },
definition: Colors.GOLD5,
keyword: Colors.VIOLET4,
plain: Colors.GOLD5,
property: Colors.TURQUOISE3,
punctuation: Colors.WHITE,
static: Colors.RED3,
string: Colors.LIME4,
tag: Colors.FOREST3,
},
};

export function SandpackButtonsExample() {
return (
<SandpackProvider
template="react-ts"
theme={theme}
options={{ visibleFiles: ["/App.tsx"] }}
customSetup={{
dependencies: {
"@blueprintjs/core": "^5.13.1",
},
}}
files={{
"/App.tsx": app,
"/index.tsx": index,
"/styles.css": styles,
}}
>
<SandpackLayout className="layout">
<SandpackCodeEditor className="editor" />
<SandpackPreview className="preview" />
</SandpackLayout>
</SandpackProvider>
);
}
4 changes: 2 additions & 2 deletions packages/docs-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"@blueprintjs/node-build-scripts": "workspace:^",
"@types/fuzzaldrin-plus": "~0.6.5",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "~5.3.3",
"webpack-cli": "^5.1.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"handlebars": "^4.7.8",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-test-renderer": "^16.14.0",
"svg-parser": "^2.0.4",
"typescript": "~5.3.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/landing-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@blueprintjs/core": "workspace:^",
"@blueprintjs/icons": "workspace:^",
"classnames": "^2.3.1",
"react": "^16.14.0",
"react-dom": "^16.14.0"
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@blueprintjs/webpack-build-scripts": "workspace:^",
Expand Down
4 changes: 2 additions & 2 deletions packages/popover2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"devDependencies": {
"@blueprintjs/node-build-scripts": "workspace:^",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "~5.3.3"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/select/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"karma": "^6.4.2",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-test-renderer": "^16.14.0",
"typescript": "~5.3.3",
"webpack-cli": "^5.1.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/table-dev-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"classnames": "^2.3.1",
"lodash": "^4.17.21",
"normalize.css": "^8.0.1",
"react": "^16.14.0",
"react-dom": "^16.14.0"
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@blueprintjs/webpack-build-scripts": "workspace:^",
Expand Down
4 changes: 2 additions & 2 deletions packages/table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
"karma": "^6.4.2",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-test-renderer": "^16.14.0",
"typescript": "~5.3.3",
"webpack": "^5.90.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/test-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"enzyme-adapter-react-16": "^1.15.7"
},
"peerDependencies": {
"react": ">=16.8",
"react-dom": ">=16.8"
"react": "^16.8 || 17 || 18",
"react-dom": "^16.8 || 17 || 18"
},
"devDependencies": {
"@blueprintjs/node-build-scripts": "workspace:^",
"npm-run-all": "^4.1.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "~5.3.3"
},
"repository": {
Expand Down
Loading