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

feat: carbon design system theme #3883

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
70759b5
feat: basic carbon theme setup
YuJianghao Sep 29, 2023
2742a54
feat: button templates
YuJianghao Sep 29, 2023
3e186a6
feat: base input template, field template
YuJianghao Sep 29, 2023
8d2e817
feat: object field template
YuJianghao Sep 30, 2023
d463caa
feat: textarea widget
YuJianghao Oct 1, 2023
54e866d
feat: description and errors
YuJianghao Oct 1, 2023
fc7d312
chore: add some dev settings
YuJianghao Oct 2, 2023
29e8070
chore: dev config
YuJianghao Oct 2, 2023
775cca9
feat: title field
YuJianghao Oct 2, 2023
31a88dd
feat: array
YuJianghao Oct 2, 2023
daf8d06
fix: style in empty object or array field
YuJianghao Oct 2, 2023
4e6f80b
feat: checkbox
YuJianghao Oct 4, 2023
fe02063
chore: add some dev settings
YuJianghao Oct 7, 2023
87c8b44
chore: remove unused emotion settings
YuJianghao Oct 7, 2023
203f437
chore: add docs and fix some pr review issues
YuJianghao Oct 7, 2023
9b0dd69
chore: update jsdoc for carbon theme
YuJianghao Oct 7, 2023
2edd67a
chore: add classNames
YuJianghao Oct 7, 2023
f6281c6
feat: radio widget
YuJianghao Oct 8, 2023
96810c1
feat: better error
YuJianghao Oct 8, 2023
d302997
chore: polish add button
YuJianghao Oct 8, 2023
022cb5d
fix: forwardRef InternalFormWrapper
YuJianghao Oct 8, 2023
3701e9d
chore: only show label in field template
YuJianghao Oct 8, 2023
ced3e88
chore: update @carbon/react version
YuJianghao Oct 9, 2023
49e7a55
chore: playground theme support form context
YuJianghao Oct 9, 2023
1d9e5ed
feat: select widget
YuJianghao Oct 9, 2023
6dc8d8a
Revert "chore: update @carbon/react version"
YuJianghao Oct 9, 2023
906cdc5
chore: add some details
YuJianghao Oct 9, 2023
b584f1b
fix: legend id conflict with input id
YuJianghao Oct 9, 2023
06cc1f9
feat: range widget and updown eidget
YuJianghao Oct 9, 2023
18cd9e7
feat: WrapIfAdditionalTemplate and some renames
YuJianghao Oct 9, 2023
c239ff5
feat: multi schema field
YuJianghao Oct 9, 2023
8606157
feat: carbon options
YuJianghao Oct 10, 2023
011ce2c
fix: checkbox style
YuJianghao Oct 18, 2023
66d3450
feat: padding
YuJianghao Oct 23, 2023
9c89616
chore: more styles
YuJianghao Oct 23, 2023
8ecad07
chore: demo build status
YuJianghao Oct 23, 2023
a563d8c
chore: little polish and continue work on pr
YuJianghao Jun 7, 2024
0f87030
chore: fix build
YuJianghao Jun 7, 2024
f29b90b
chore: fix build
YuJianghao Jun 7, 2024
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
351 changes: 347 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"workspaces": [
"packages/antd",
"packages/bootstrap-4",
"packages/carbon",
"packages/chakra-ui",
"packages/core",
"packages/docs",
Expand Down
4 changes: 4 additions & 0 deletions packages/carbon/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../../.eslintrc"],
"plugins": ["@typescript-eslint", "jsx-a11y", "react", "import"]
}
164 changes: 164 additions & 0 deletions packages/carbon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
[![Build Status][build-shield]][build-url]
[![npm][npm-shield]][npm-url]
[![npm downloads][npm-dl-shield]][npm-dl-url]
[![Contributors][contributors-shield]][contributors-url]
[![Apache 2.0 License][license-shield]][license-url]

<!-- PROJECT LOGO -->
<br />
<p align="center">
<a href="https://github.com/rjsf-team/react-jsonschema-form">
<img src="./logo.png" alt="Logo" width="340">
</a>

<h3 align="center">@rjsf/chakra-ui</h3>

<p align="center">
Chakra UI theme, fields and widgets for <a href="https://github.com/rjsf-team/react-jsonschema-form/"><code>react-jsonschema-form</code></a>.
<br />
<a href="https://rjsf-team.github.io/react-jsonschema-form/docs/"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://rjsf-team.github.io/react-jsonschema-form/">View Playground</a>
·
<a href="https://github.com/rjsf-team/react-jsonschema-form/issues">Report Bug</a>
·
<a href="https://github.com/rjsf-team/react-jsonschema-form/issues">Request Feature</a>
</p>
</p>

<!-- TABLE OF CONTENTS -->

## Table of Contents

- [Table of Contents](#table-of-contents)
- [About The Project](#about-the-project)
- [Built With](#built-with)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)
- [Optional Chakra UI Theme properties](#optional-chakra-ui-theme-properties)
- [Custom Chakra uiSchema Chakra Property](#custom-chakra-uischema-chakra-property)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [Contact](#contact)

<!-- ABOUT THE PROJECT -->

## About The Project

[![@rjsf/chakra-ui Screen Shot][product-screenshot]](https://rjsf-team.github.io/@rjsf/chakra-ui)

Exports `chakra-ui` theme, fields and widgets for `react-jsonschema-form`.

### Built With

- [react-jsonschema-form](https://github.com/rjsf-team/react-jsonschema-form/)
- [Chakra UI](https://chakra-ui.com/)
- [TypeScript](https://www.typescriptlang.org/)

<!-- GETTING STARTED -->

## Getting Started

### Prerequisites

- `@chakra-ui/react >= 1.7.0`
- `chakra-react-select >= 3.3.8`
- `react >= 17.0.0`
- `framer-motion >= 5.0.0`
- `@rjsf/core >= 2.0.0`

Refer to the [rjsf installation guide](https://rjsf-team.github.io/react-jsonschema-form/docs/#installation) and [chakra-ui installation guide](https://chakra-ui.com/docs/getting-started#installation) and for more details.

---

### Installation

```bash
yarn add @chakra-ui/react@^1.7 @emotion/react@^11 @emotion/styled@^11 framer-motion@^5
```

```bash
yarn add @rjsf/chakra-ui @rjsf/core
```

<!-- USAGE EXAMPLES -->

## Usage

```js
import Form from '@rjsf/chakra-ui';
```

or

```js
import { withTheme } from '@rjsf/core';
import { Theme as ChakraUITheme } from '@rjsf/chakra-ui';

// Make modifications to the theme with your own fields and widgets

const Form = withTheme(ChakraUITheme);
```

## Optional Chakra UI Theme properties

- To pass additional properties to widgets, see this [guide](https://rjsf-team.github.io/react-jsonschema-form/docs/usage/objects#additional-properties).

You can use `ChakraProvider`, to customize the components at a theme level.\
And, `uiSchema` allows for the use of a `"chakra"` `"ui:option"` to customize the styling of the form widgets.

#### Custom Chakra uiSchema Chakra Property

```json
{
"ui:options": {
"chakra": {
"p": "1rem",
"color": "blue.200",
"sx": {
"margin": "0 auto"
}
}
}
}
```

It accepts the theme accessible [style props](https://chakra-ui.com/docs/features/style-props) provided by [Chakra](https://chakra-ui.com/docs/getting-started) and [Emotion](https://emotion.sh/docs/introduction).

<!-- ROADMAP -->

## Roadmap

See the [open issues](https://github.com/rjsf-team/react-jsonschema-form/issues) for a list of proposed features (and known issues).

<!-- CONTRIBUTING -->

## Contributing

Read our [contributors' guide](https://rjsf-team.github.io/react-jsonschema-form/docs/contributing/) to get started.

<!-- CONTACT -->

## Contact

rjsf team: [https://github.com/orgs/rjsf-team/people](https://github.com/orgs/rjsf-team/people)

GitHub repository: [https://github.com/rjsf-team/react-jsonschema-form](https://github.com/rjsf-team/react-jsonschema-form)

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->

[build-shield]: https://github.com/rjsf-team/react-jsonschema-form/workflows/CI/badge.svg
[build-url]: https://github.com/rjsf-team/react-jsonschema-form/actions
[contributors-shield]: https://img.shields.io/github/contributors/rjsf-team/react-jsonschema-form.svg
[contributors-url]: https://github.com/rjsf-team/react-jsonschema-form/graphs/contributors
[license-shield]: https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square
[license-url]: https://choosealicense.com/licenses/apache-2.0/
[npm-shield]: https://img.shields.io/npm/v/@rjsf/chakra-ui/latest.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@rjsf/chakra-ui
[npm-dl-shield]: https://img.shields.io/npm/dm/@rjsf/chakra-ui.svg?style=flat-square
[npm-dl-url]: https://www.npmjs.com/package/@rjsf/chakra-ui
[product-screenshot]: ./screenshot.png
3 changes: 3 additions & 0 deletions packages/carbon/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const defaultConfig = require('../../babel.config');

module.exports = defaultConfig;
7 changes: 7 additions & 0 deletions packages/carbon/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
browsers: ['chrome', 'firefox', 'safari'],
},
transformIgnorePatterns: [`/node_modules/(?!nanoid)`],
};
Binary file added packages/carbon/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions packages/carbon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "@rjsf/carbon",
"version": "5.18.4",
"description": "Carbon Design UI theme, fields, and widgets for react-jsonschema-form",
"main": "dist/index.js",
"module": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
"dist",
"lib",
"src"
],
"scripts": {
"build:ts": "tsc -b",
"build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.js --sourcemap --packages=external --format=cjs",
"build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/carbon.esm.js --sourcemap --packages=external --format=esm",
"build:umd": "rollup dist/carbon.esm.js --format=umd --file=dist/carbon.umd.js --name=@rjsf/carbon",
"build": "npm run build:ts && npm run build:cjs && npm run build:esm && npm run build:umd",
"cs-check": "prettier -l \"{src,test}/**/*.ts?(x)\"",
"cs-format": "prettier \"{src,test}/**/*.ts?(x)\" --write",
"lint": "eslint src test",
"precommit": "lint-staged",
"test": "jest",
"test:update": "jest --u",
"test:watch": "jest --watch"
},
"lint-staged": {
"{src,test}/**/*.ts?(x)": [
"eslint --fix"
]
},
"engineStrict": false,
"engines": {
"node": ">=14"
},
"peerDependencies": {
"@carbon/icons-react": "11.43.0",
"@carbon/react": "1.59.0",
"@rjsf/core": "^5.18.x",
"@rjsf/utils": "^5.18.x",
"react": "^16.14.0 || >=17"
},
"publishConfig": {
"access": "public"
},
"author": "Jianghao Yu <[email protected]>",
"license": "Apache-2.0",
"devDependencies": {
"@babel/core": "^7.23.9",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/preset-env": "^7.23.9",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@carbon/icons-react": "11.43.0",
"@carbon/react": "1.59.0",
"@rjsf/core": "^5.18.4",
"@rjsf/snapshot-tests": "^5.18.4",
"@rjsf/utils": "^5.18.4",
"@rjsf/validator-ajv8": "^5.18.4",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.58",
"@types/react-dom": "^18.2.19",
"@types/react-test-renderer": "^18.0.7",
"babel-jest": "^29.7.0",
"esbuild": "^0.18.20",
"eslint": "^8.56.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-watch-typeahead": "^2.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"rimraf": "^5.0.5",
"rollup": "^3.29.4",
"typescript": "^4.9.5"
}
}
Binary file added packages/carbon/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions packages/carbon/src/AddButton/AddButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Add } from '@carbon/icons-react';
import { Button } from '@carbon/react';
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';

/** Implement `ButtonTemplates.AddButton`
*/
export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add Documentation similar to what is in other themes?

uiSchema,
registry,
...props
}: IconButtonProps<T, S, F>) {
const { translateString } = registry;
return (
<Button size='sm' kind='tertiary' renderIcon={Add} {...props}>
{translateString(TranslatableString.AddItemButton)}
</Button>
);
}
2 changes: 2 additions & 0 deletions packages/carbon/src/AddButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './AddButton';
export * from './AddButton';
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useMemo } from 'react';
import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';

/** Implement `ArrayFieldItemTemplate`
*/
export default function ArrayFieldItemTemplate<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add Documentation similar to what is in other themes?

T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: ArrayFieldTemplateItemType<T, S, F>) {
const {
className,
children,
disabled,
hasToolbar,
hasCopy,
hasMoveDown,
hasMoveUp,
hasRemove,
index,
onCopyIndexClick,
onDropIndexClick,
onReorderClick,
readonly,
uiSchema,
registry,
} = props;
const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates;
const onCopyClick = useMemo(() => onCopyIndexClick(index), [index, onCopyIndexClick]);

const onRemoveClick = useMemo(() => onDropIndexClick(index), [index, onDropIndexClick]);

const onArrowUpClick = useMemo(() => onReorderClick(index, index - 1), [index, onReorderClick]);

const onArrowDownClick = useMemo(() => onReorderClick(index, index + 1), [index, onReorderClick]);

return (
<div className={className} style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'center' }}>
<div style={{ flex: 1 }}>{children}</div>
{hasToolbar && (
<div
className='array-item-toolbox'
style={{
marginLeft: '1rem',
maxWidth: '4rem',
}}
>
{(hasMoveUp || hasMoveDown) && (
<MoveUpButton
disabled={disabled || readonly || !hasMoveUp}
onClick={onArrowUpClick}
uiSchema={uiSchema}
registry={registry}
/>
)}
{(hasMoveUp || hasMoveDown) && (
<MoveDownButton
disabled={disabled || readonly || !hasMoveDown}
onClick={onArrowDownClick}
uiSchema={uiSchema}
registry={registry}
/>
)}
{hasCopy && (
<CopyButton disabled={disabled || readonly} onClick={onCopyClick} uiSchema={uiSchema} registry={registry} />
)}
{hasRemove && (
<RemoveButton
disabled={disabled || readonly}
onClick={onRemoveClick}
uiSchema={uiSchema}
registry={registry}
/>
)}
<span />
</div>
)}
</div>
);
}
2 changes: 2 additions & 0 deletions packages/carbon/src/ArrayFieldItemTemplate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './ArrayFieldItemTemplate';
export * from './ArrayFieldItemTemplate';
Loading
Loading