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

Props panel sections #855

Merged
merged 4 commits into from
Aug 30, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack, styled, Typography } from '@mui/material';
import { Stack, styled, Typography, Divider } from '@mui/material';
import * as React from 'react';
import { ArgTypeDefinition, ArgTypeDefinitions, ComponentConfig } from '@mui/toolpad-core';
import { ExactEntriesOf } from '../../../utils/types';
Expand All @@ -20,11 +20,15 @@ import {

const classes = {
control: 'Toolpad_Control',
sectionHeading: 'Toolpad_ControlsSectionHeading',
};

const ComponentPropsEditorRoot = styled('div')(({ theme }) => ({
const ComponentEditorRoot = styled('div')(({ theme }) => ({
[`& .${classes.control}`]: {
margin: theme.spacing(1, 0),
margin: theme.spacing(0, 0),
},
[`& .${classes.sectionHeading}`]: {
margin: theme.spacing(0, 0, -0.5, 0),
},
}));

Expand All @@ -50,10 +54,10 @@ function ComponentPropsEditor<P>({ componentConfig, node }: ComponentPropsEditor
const hasLayoutControls = hasLayoutHorizontalControls || hasLayoutVerticalControls;

return (
<ComponentPropsEditorRoot>
<React.Fragment>
{hasLayoutControls ? (
<React.Fragment>
<Typography variant="subtitle2" sx={{ mt: 1 }}>
<Typography variant="overline" className={classes.sectionHeading}>
Layout:
</Typography>
{hasLayoutHorizontalControls ? (
Expand All @@ -76,9 +80,10 @@ function ComponentPropsEditor<P>({ componentConfig, node }: ComponentPropsEditor
/>
</div>
) : null}
<Divider sx={{ mt: 1 }} />
</React.Fragment>
) : null}
<Typography variant="subtitle2" sx={{ mt: hasLayoutControls ? 2 : 1 }}>
<Typography variant="overline" className={classes.sectionHeading}>
Properties:
</Typography>
{(Object.entries(componentConfig.argTypes) as ExactEntriesOf<ArgTypeDefinitions<P>>).map(
Expand All @@ -94,7 +99,7 @@ function ComponentPropsEditor<P>({ componentConfig, node }: ComponentPropsEditor
</div>
) : null,
)}
</ComponentPropsEditorRoot>
</React.Fragment>
);
}

Expand All @@ -115,11 +120,12 @@ function SelectedNodeEditor({ node }: SelectedNodeEditorProps) {
<Typography variant="subtitle1">
Component: {component?.displayName || '<unknown>'}
</Typography>
<Typography variant="subtitle2" sx={{ mb: 2 }}>
<Typography variant="subtitle2" sx={{ mb: 1 }}>
ID: {node.id}
</Typography>
<NodeNameEditor node={node} />
{nodeError ? <ErrorAlert error={nodeError} /> : null}
<Divider sx={{ mt: 1 }} />
{node ? (
<React.Fragment>
<ComponentPropsEditor componentConfig={componentConfig} node={node} />
Expand All @@ -142,13 +148,13 @@ export default function ComponentEditor({ className }: ComponentEditorProps) {
const selectedNode = selection ? appDom.getNode(dom, selection) : null;

return (
<div className={className}>
<ComponentEditorRoot className={className}>
{selectedNode && appDom.isElement(selectedNode) ? (
// Add key to make sure it mounts every time selected node changes
<SelectedNodeEditor key={selectedNode.id} node={selectedNode} />
) : (
<PageOptionsPanel />
)}
</div>
</ComponentEditorRoot>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function HorizontalAlignPropEditor({

return (
<Box>
<Typography>{label}:</Typography>
<Typography variant="body2">{label}:</Typography>
<ToggleButtonGroup
exclusive
disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function VerticalAlignPropEditor({

return (
<Box>
<Typography>{label}:</Typography>
<Typography variant="body2">{label}:</Typography>
<ToggleButtonGroup
exclusive
disabled={disabled}
Expand Down
18 changes: 9 additions & 9 deletions packages/toolpad-components/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ function Button({ content, ...rest }: ButtonProps) {
export default createComponent(Button, {
layoutDirection: 'both',
argTypes: {
onClick: {
typeDef: { type: 'event' },
},
content: {
typeDef: { type: 'string' },
defaultValue: 'Button Text',
},
onClick: {
typeDef: { type: 'event' },
},
variant: {
typeDef: { type: 'string', enum: ['contained', 'outlined', 'text'] },
defaultValue: 'contained',
},
disabled: {
typeDef: { type: 'boolean' },
},
fullWidth: {
typeDef: { type: 'boolean' },
},
color: {
typeDef: { type: 'string', enum: ['primary', 'secondary'] },
defaultValue: 'primary',
},
fullWidth: {
typeDef: { type: 'boolean' },
},
loading: {
typeDef: { type: 'boolean' },
},
disabled: {
typeDef: { type: 'boolean' },
},
sx: {
typeDef: { type: 'object' },
},
Expand Down
24 changes: 12 additions & 12 deletions packages/toolpad-components/src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ export default createComponent(DataGridComponent, {
typeDef: { type: 'array', schema: '/schemas/DataGridColumns.json' },
control: { type: 'GridColumns' },
},
rowIdField: {
typeDef: { type: 'string' },
control: { type: 'RowIdFieldSelect' },
label: 'Id field',
},
selection: {
typeDef: { type: 'object' },
onChangeProp: 'onSelectionChange',
defaultValue: null,
},
density: {
typeDef: { type: 'string', enum: ['compact', 'standard', 'comfortable'] },
defaultValue: 'compact',
Expand All @@ -346,21 +356,11 @@ export default createComponent(DataGridComponent, {
typeDef: { type: 'number' },
defaultValue: 350,
},
sx: {
typeDef: { type: 'object' },
},
selection: {
typeDef: { type: 'object' },
onChangeProp: 'onSelectionChange',
defaultValue: null,
},
loading: {
typeDef: { type: 'boolean' },
},
rowIdField: {
typeDef: { type: 'string' },
control: { type: 'RowIdFieldSelect' },
label: 'Id field',
sx: {
typeDef: { type: 'object' },
},
},
});
30 changes: 15 additions & 15 deletions packages/toolpad-components/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,34 @@ export default createComponent(Select, {
loadingPropSource: ['value', 'options'],
loadingProp: 'disabled',
argTypes: {
label: {
options: {
typeDef: { type: 'array', schema: '/schemas/SelectOptions.json' },
control: { type: 'SelectOptions' },
defaultValue: [],
},
value: {
typeDef: { type: 'string' },
onChangeProp: 'onChange',
onChangeHandler: (event: React.ChangeEvent<HTMLSelectElement>) => event.target.value,
defaultValue: '',
},
disabled: {
typeDef: { type: 'boolean' },
label: {
typeDef: { type: 'string' },
defaultValue: '',
},
variant: {
typeDef: { type: 'string', enum: ['outlined', 'filled', 'standard'] },
defaultValue: 'outlined',
},
fullWidth: {
typeDef: { type: 'boolean' },
},
size: {
typeDef: { type: 'string', enum: ['small', 'medium'] },
defaultValue: 'small',
},
value: {
typeDef: { type: 'string' },
onChangeProp: 'onChange',
onChangeHandler: (event: React.ChangeEvent<HTMLSelectElement>) => event.target.value,
defaultValue: '',
fullWidth: {
typeDef: { type: 'boolean' },
},
options: {
typeDef: { type: 'array', schema: '/schemas/SelectOptions.json' },
control: { type: 'SelectOptions' },
defaultValue: [],
disabled: {
typeDef: { type: 'boolean' },
},
sx: {
typeDef: { type: 'object' },
Expand Down
14 changes: 7 additions & 7 deletions packages/toolpad-components/src/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import { createComponent } from '@mui/toolpad-core';

export default createComponent(Stack, {
argTypes: {
gap: {
typeDef: { type: 'number' },
defaultValue: 2,
},
margin: {
typeDef: { type: 'number' },
},
direction: {
typeDef: {
type: 'string',
Expand All @@ -31,6 +24,13 @@ export default createComponent(Stack, {
},
defaultValue: 'start',
},
gap: {
typeDef: { type: 'number' },
defaultValue: 2,
},
margin: {
typeDef: { type: 'number' },
},
children: {
typeDef: { type: 'element' },
control: { type: 'slots' },
Expand Down
22 changes: 11 additions & 11 deletions packages/toolpad-components/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ function TextField(props: TextFieldProps) {
export default createComponent(TextField, {
layoutDirection: 'both',
argTypes: {
value: {
typeDef: { type: 'string' },
onChangeProp: 'onChange',
onChangeHandler: (event: React.ChangeEvent<HTMLInputElement>) => event.target.value,
defaultValue: '',
},
label: {
typeDef: { type: 'string' },
},
variant: {
typeDef: { type: 'string', enum: ['outlined', 'filled', 'standard'] },
defaultValue: 'outlined',
},
disabled: {
typeDef: { type: 'boolean' },
},
fullWidth: {
typeDef: { type: 'boolean' },
},
size: {
typeDef: { type: 'string', enum: ['small', 'normal'] },
defaultValue: 'small',
},
value: {
typeDef: { type: 'string' },
onChangeProp: 'onChange',
onChangeHandler: (event: React.ChangeEvent<HTMLInputElement>) => event.target.value,
defaultValue: '',
fullWidth: {
typeDef: { type: 'boolean' },
},
disabled: {
typeDef: { type: 'boolean' },
},
sx: {
typeDef: { type: 'object' },
Expand Down