-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add playground examples for LayoutGrid for each theme #4509
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
Conversation
Updated the `playground` so that each theme has an example of the `LayoutGridField` usage - In `@rjsf/utils` added a `browser` section to the `package.json` to support `getTestIds()` working properly in a browser - Updated the `getTestIds()` to refactor out `getTestIdsBrowser()` and export it from the new `indexBrowser.ts` - Updated `package.json` to build `indexBrowser.js` for each export type - In `@rjsf/core` made a few changes to support the playground examples: - In `LayoutMultiSchemaField` added support for the hiding of labels as well as extracting the `placeholder` from the UiSchema - In `GridTemplate` removed the explicit adding of the `row` class, leaving that up to the users of the `UiSchema` - In `@rjsf/fluentui-rc` made a few changes to support the playground examples: - In `GridTemplate` switched to using the `GridShim` displaying it only when `columns` or `rows` are provided, otherwise simply exporting a `div` due to the CSS Grid - In `RadioWidget` implemented support for `inline` styling of the radio elements - In `playground` implemented the `Layout Grid` example with the following changes: - Updated the `vite.config.ts` to pull the `utils` classes from the `indexBrowser` - Added the new `UiSchemaForTheme` type, overriding the `uiSchema` for `Sample` to be `UiSchema` or `UiSchemaForTheme` - Renamed `Selector` to `SampleSelector`, adding the `selectedSample` as a prop, removing the use of the `current` state in favor of `selectedSample` - Also changed the `onSelected()` callback to take a `sampleName: string` rather than `data: any` - Updated `Header` to replace `load` with `onSampleSelected` adding `sampleName: string`, serializing `sampleName` on share - Also, passed `sampleName` as `selectedSample` and `onSampleSelected` to the `SampleSelector` - Updated `EditorProps` to take `data: any` for `onChange` - Updated `EditorsProps` to take a new `hasUiSchemaGenerator: boolean`, using it to provide a different title for the `UiSchema` section when true - Updated `Playground` add two new state variables, `uiSchemaGenerator` and `sampleName` - Updated `onThemeSelected()` to update the `uiSchema` to the one generated from the `uiSchemaGenerator(theme)` if that function is defined in state - Updated `load()` to take an additional `sampleName` prop, using it to set the currently selected sample and to set the `uiSchemaGenerator` if `samples[sampleName]` has one - Also, set the `uiSchema` to a generated one if the incoming `uiSchema` is a function and adding a undefined check for the `validator` - Added a new `onSampleSelected()` which calls `load()` with the selected sample and `sampleName` - Updated `DemoFrame` and `app.ts` to rename `material-ui-5` to `mui` - Added a new `layoutGrid.ts` and exported it from the `samples/index.ts`
I dislike this implementation for the grid. For v5 the UI schema works for all themes. Custom ui options are ignored for other themes. That's not the case for this grid implementation. Additionally, it doesn't provide proper options for different screen sizes for all themes, which is a must for a grid layout. I would suggest assuming a 1/12th grid, and only allow setting the span to Limiting the options makes more sense. The grid should look decent, instead of focussing on finetuned customized styling. For that people can overwrite the template.
|
@jasny Here's the issue I see with your approach; the Fluent and Chakra-UI are both using native CSS grids which do NOT have a 1-12 approach. And At the end of the day, the UiSchema is about modifying the standard UI approach for RJSF to fit the specifics of the UI the developer wants. I imagine that 99% of people using RJSF do so with a single theme making the need for a theme-agnostic grid approach mute. Therefore, providing a way for users to fine tune the gridding to exactly what they want, I believe, is the best approach. Making it a least-common-denominator (LCD) solution like you are suggesting won't help people make exactly the UIs they want. It likely will even hinder it. With this grid approach I've developed one can put any field into any position. Using my example... If you wanted to move the In terms of providing "proper options for different screen sizes for all themes", again, that is up to the developer to build. All of the themes that use the 1-12 grid system support the screen breakpoints, which the developer can easily add to their UI schema. Yes, it likely will take some playing around with the fine grain details of the All that said, I definitely want to chat more about your ideas around how imagine see it work and how you might use it. Perhaps we do add support for the simplest LCD approach with a
|
} | ||
|
||
export default function Selector({ onSelected }: SelectorProps) { | ||
const [current, setCurrent] = useState<string>('Simple'); |
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.
thanks for making this controlled
import getSchemaType from './getSchemaType'; | ||
import getSubmitButtonOptions from './getSubmitButtonOptions'; | ||
import getTemplate from './getTemplate'; | ||
import { getTestIdsBrowser as getTestIds } from './getTestIds'; |
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.
Why doesn't getTestIds
work in the browser?
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.
Browsers don't have process
defined and using it there cause a TypeError and the playground wouldn't start
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.
LGTM, I agree with @jasny though that it's a good idea to explore augmenting this with a more simple/conventional API.
* Add playground examples for LayoutGrid for each theme Updated the `playground` so that each theme has an example of the `LayoutGridField` usage - In `@rjsf/utils` added a `browser` section to the `package.json` to support `getTestIds()` working properly in a browser - Updated the `getTestIds()` to refactor out `getTestIdsBrowser()` and export it from the new `indexBrowser.ts` - Updated `package.json` to build `indexBrowser.js` for each export type - In `@rjsf/core` made a few changes to support the playground examples: - In `LayoutMultiSchemaField` added support for the hiding of labels as well as extracting the `placeholder` from the UiSchema - In `GridTemplate` removed the explicit adding of the `row` class, leaving that up to the users of the `UiSchema` - In `@rjsf/fluentui-rc` made a few changes to support the playground examples: - In `GridTemplate` switched to using the `GridShim` displaying it only when `columns` or `rows` are provided, otherwise simply exporting a `div` due to the CSS Grid - In `RadioWidget` implemented support for `inline` styling of the radio elements - In `playground` implemented the `Layout Grid` example with the following changes: - Updated the `vite.config.ts` to pull the `utils` classes from the `indexBrowser` - Added the new `UiSchemaForTheme` type, overriding the `uiSchema` for `Sample` to be `UiSchema` or `UiSchemaForTheme` - Renamed `Selector` to `SampleSelector`, adding the `selectedSample` as a prop, removing the use of the `current` state in favor of `selectedSample` - Also changed the `onSelected()` callback to take a `sampleName: string` rather than `data: any` - Updated `Header` to replace `load` with `onSampleSelected` adding `sampleName: string`, serializing `sampleName` on share - Also, passed `sampleName` as `selectedSample` and `onSampleSelected` to the `SampleSelector` - Updated `EditorProps` to take `data: any` for `onChange` - Updated `EditorsProps` to take a new `hasUiSchemaGenerator: boolean`, using it to provide a different title for the `UiSchema` section when true - Updated `Playground` add two new state variables, `uiSchemaGenerator` and `sampleName` - Updated `onThemeSelected()` to update the `uiSchema` to the one generated from the `uiSchemaGenerator(theme)` if that function is defined in state - Updated `load()` to take an additional `sampleName` prop, using it to set the currently selected sample and to set the `uiSchemaGenerator` if `samples[sampleName]` has one - Also, set the `uiSchema` to a generated one if the incoming `uiSchema` is a function and adding a undefined check for the `validator` - Added a new `onSampleSelected()` which calls `load()` with the selected sample and `sampleName` - Updated `DemoFrame` and `app.ts` to rename `material-ui-5` to `mui` - Added a new `layoutGrid.ts` and exported it from the `samples/index.ts` * - Fixed test * Update CHANGELOG_v6.md * - Fix `MultiSchemaField` to pass `id` in `onChange` * - Renamed `MuiV5Theme` to `MuiTheme`
* Add playground examples for LayoutGrid for each theme Updated the `playground` so that each theme has an example of the `LayoutGridField` usage - In `@rjsf/utils` added a `browser` section to the `package.json` to support `getTestIds()` working properly in a browser - Updated the `getTestIds()` to refactor out `getTestIdsBrowser()` and export it from the new `indexBrowser.ts` - Updated `package.json` to build `indexBrowser.js` for each export type - In `@rjsf/core` made a few changes to support the playground examples: - In `LayoutMultiSchemaField` added support for the hiding of labels as well as extracting the `placeholder` from the UiSchema - In `GridTemplate` removed the explicit adding of the `row` class, leaving that up to the users of the `UiSchema` - In `@rjsf/fluentui-rc` made a few changes to support the playground examples: - In `GridTemplate` switched to using the `GridShim` displaying it only when `columns` or `rows` are provided, otherwise simply exporting a `div` due to the CSS Grid - In `RadioWidget` implemented support for `inline` styling of the radio elements - In `playground` implemented the `Layout Grid` example with the following changes: - Updated the `vite.config.ts` to pull the `utils` classes from the `indexBrowser` - Added the new `UiSchemaForTheme` type, overriding the `uiSchema` for `Sample` to be `UiSchema` or `UiSchemaForTheme` - Renamed `Selector` to `SampleSelector`, adding the `selectedSample` as a prop, removing the use of the `current` state in favor of `selectedSample` - Also changed the `onSelected()` callback to take a `sampleName: string` rather than `data: any` - Updated `Header` to replace `load` with `onSampleSelected` adding `sampleName: string`, serializing `sampleName` on share - Also, passed `sampleName` as `selectedSample` and `onSampleSelected` to the `SampleSelector` - Updated `EditorProps` to take `data: any` for `onChange` - Updated `EditorsProps` to take a new `hasUiSchemaGenerator: boolean`, using it to provide a different title for the `UiSchema` section when true - Updated `Playground` add two new state variables, `uiSchemaGenerator` and `sampleName` - Updated `onThemeSelected()` to update the `uiSchema` to the one generated from the `uiSchemaGenerator(theme)` if that function is defined in state - Updated `load()` to take an additional `sampleName` prop, using it to set the currently selected sample and to set the `uiSchemaGenerator` if `samples[sampleName]` has one - Also, set the `uiSchema` to a generated one if the incoming `uiSchema` is a function and adding a undefined check for the `validator` - Added a new `onSampleSelected()` which calls `load()` with the selected sample and `sampleName` - Updated `DemoFrame` and `app.ts` to rename `material-ui-5` to `mui` - Added a new `layoutGrid.ts` and exported it from the `samples/index.ts` * - Fixed test * Update CHANGELOG_v6.md * - Fix `MultiSchemaField` to pass `id` in `onChange` * - Renamed `MuiV5Theme` to `MuiTheme`
Reasons for making this change
Updated the
playground
so that each theme has an example of theLayoutGridField
usage@rjsf/utils
added abrowser
section to thepackage.json
to supportgetTestIds()
working properly in a browsergetTestIds()
to refactor outgetTestIdsBrowser()
and export it from the newindexBrowser.ts
package.json
to buildindexBrowser.js
for each export type@rjsf/core
made a few changes to support the playground examples:LayoutMultiSchemaField
added support for the hiding of labels as well as extracting theplaceholder
from the UiSchemaGridTemplate
removed the explicit adding of therow
class, leaving that up to the users of theUiSchema
@rjsf/fluentui-rc
made a few changes to support the playground examples:GridTemplate
switched to using theGridShim
displaying it only whencolumns
orrows
are provided, otherwise simply exporting adiv
due to the CSS GridRadioWidget
implemented support forinline
styling of the radio elementsplayground
implemented theLayout Grid
example with the following changes:vite.config.ts
to pull theutils
classes from theindexBrowser
UiSchemaForTheme
type, overriding theuiSchema
forSample
to beUiSchema
orUiSchemaForTheme
Selector
toSampleSelector
, adding theselectedSample
as a prop, removing the use of thecurrent
state in favor ofselectedSample
onSelected()
callback to take asampleName: string
rather thandata: any
Header
to replaceload
withonSampleSelected
addingsampleName: string
, serializingsampleName
on sharesampleName
asselectedSample
andonSampleSelected
to theSampleSelector
EditorProps
to takedata: any
foronChange
EditorsProps
to take a newhasUiSchemaGenerator: boolean
, using it to provide a different title for theUiSchema
section when truePlayground
add two new state variables,uiSchemaGenerator
andsampleName
onThemeSelected()
to update theuiSchema
to the one generated from theuiSchemaGenerator(theme)
if that function is defined in stateload()
to take an additionalsampleName
prop, using it to set the currently selected sample and to set theuiSchemaGenerator
ifsamples[sampleName]
has oneuiSchema
to a generated one if the incominguiSchema
is a function and adding a undefined check for thevalidator
onSampleSelected()
which callsload()
with the selected sample andsampleName
DemoFrame
andapp.ts
to renamematerial-ui-5
tomui
layoutGrid.ts
and exported it from thesamples/index.ts
Checklist
npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update
to update snapshots, if needed.