-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
YuJianghao
wants to merge
39
commits into
rjsf-team:main
Choose a base branch
from
YuJianghao:carbon
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 2742a54
feat: button templates
YuJianghao 3e186a6
feat: base input template, field template
YuJianghao 8d2e817
feat: object field template
YuJianghao d463caa
feat: textarea widget
YuJianghao 54e866d
feat: description and errors
YuJianghao fc7d312
chore: add some dev settings
YuJianghao 29e8070
chore: dev config
YuJianghao 775cca9
feat: title field
YuJianghao 31a88dd
feat: array
YuJianghao daf8d06
fix: style in empty object or array field
YuJianghao 4e6f80b
feat: checkbox
YuJianghao fe02063
chore: add some dev settings
YuJianghao 87c8b44
chore: remove unused emotion settings
YuJianghao 203f437
chore: add docs and fix some pr review issues
YuJianghao 9b0dd69
chore: update jsdoc for carbon theme
YuJianghao 2edd67a
chore: add classNames
YuJianghao f6281c6
feat: radio widget
YuJianghao 96810c1
feat: better error
YuJianghao d302997
chore: polish add button
YuJianghao 022cb5d
fix: forwardRef InternalFormWrapper
YuJianghao 3701e9d
chore: only show label in field template
YuJianghao ced3e88
chore: update @carbon/react version
YuJianghao 49e7a55
chore: playground theme support form context
YuJianghao 1d9e5ed
feat: select widget
YuJianghao 6dc8d8a
Revert "chore: update @carbon/react version"
YuJianghao 906cdc5
chore: add some details
YuJianghao b584f1b
fix: legend id conflict with input id
YuJianghao 06cc1f9
feat: range widget and updown eidget
YuJianghao 18cd9e7
feat: WrapIfAdditionalTemplate and some renames
YuJianghao c239ff5
feat: multi schema field
YuJianghao 8606157
feat: carbon options
YuJianghao 011ce2c
fix: checkbox style
YuJianghao 66d3450
feat: padding
YuJianghao 9c89616
chore: more styles
YuJianghao 8ecad07
chore: demo build status
YuJianghao a563d8c
chore: little polish and continue work on pr
YuJianghao 0f87030
chore: fix build
YuJianghao f29b90b
chore: fix build
YuJianghao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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
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": ["../../.eslintrc"], | ||
"plugins": ["@typescript-eslint", "jsx-a11y", "react", "import"] | ||
} |
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,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 |
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 @@ | ||
const defaultConfig = require('../../babel.config'); | ||
|
||
module.exports = defaultConfig; |
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,7 @@ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
testEnvironmentOptions: { | ||
browsers: ['chrome', 'firefox', 'safari'], | ||
}, | ||
transformIgnorePatterns: [`/node_modules/(?!nanoid)`], | ||
}; |
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,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" | ||
} | ||
} |
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,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>({ | ||
uiSchema, | ||
registry, | ||
...props | ||
}: IconButtonProps<T, S, F>) { | ||
const { translateString } = registry; | ||
return ( | ||
<Button size='sm' kind='tertiary' renderIcon={Add} {...props}> | ||
{translateString(TranslatableString.AddItemButton)} | ||
</Button> | ||
); | ||
} |
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,2 @@ | ||
export { default } from './AddButton'; | ||
export * from './AddButton'; |
80 changes: 80 additions & 0 deletions
80
packages/carbon/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.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,80 @@ | ||
import { useMemo } from 'react'; | ||
import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils'; | ||
|
||
/** Implement `ArrayFieldItemTemplate` | ||
*/ | ||
export default function ArrayFieldItemTemplate< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
); | ||
} |
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,2 @@ | ||
export { default } from './ArrayFieldItemTemplate'; | ||
export * from './ArrayFieldItemTemplate'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?