make task show wide, and make repeating form icons match site styles. w/ dfunk

This commit is contained in:
burnettk 2023-01-30 15:51:48 -05:00
parent de607ded0f
commit b43f7b6cf5
5 changed files with 173 additions and 90 deletions

View File

@ -217,7 +217,7 @@ export default function TaskShow() {
return ( return (
<Grid fullWidth condensed> <Grid fullWidth condensed>
<Column md={5} lg={8} sm={4}> <Column sm={4} md={8} lg={16}>
<Form <Form
formData={taskData} formData={taskData}
onSubmit={handleFormSubmit} onSubmit={handleFormSubmit}

View File

@ -1,17 +1,36 @@
import React from 'react'; import React from 'react';
import AddIcon from '@mui/icons-material/Add'; import {
import IconButton from '@mui/material/IconButton'; FormContextType,
import { IconButtonProps } from '@rjsf/utils'; IconButtonProps,
RJSFSchema,
StrictRJSFSchema,
} from '@rjsf/utils';
const AddButton: React.ComponentType<IconButtonProps> = ({ // @ts-ignore
uiSchema, import { AddAlt } from '@carbon/icons-react';
...props
}) => { import IconButton from '../IconButton/IconButton';
/** The `AddButton` renders a button that represent the `Add` action on a form
*/
export default function AddButton<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>({ className, onClick, disabled, registry }: IconButtonProps<T, S, F>) {
return ( return (
<IconButton title="Add Item" {...props} color="primary"> <div className="row">
<AddIcon /> <p className={`col-xs-3 col-xs-offset-9 text-right ${className}`}>
</IconButton> <IconButton
iconType="info"
icon="plus"
className="btn-add col-xs-12"
title="Add"
onClick={onClick}
disabled={disabled}
registry={registry}
/>
</p>
</div>
); );
}; }
export default AddButton;

View File

@ -5,6 +5,11 @@ import {
RJSFSchema, RJSFSchema,
StrictRJSFSchema, StrictRJSFSchema,
} from '@rjsf/utils'; } from '@rjsf/utils';
import {
Grid,
Column,
// @ts-ignore
} from '@carbon/react';
/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array. /** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
* *
@ -33,53 +38,67 @@ export default function ArrayFieldItemTemplate<
const { MoveDownButton, MoveUpButton, RemoveButton } = const { MoveDownButton, MoveUpButton, RemoveButton } =
registry.templates.ButtonTemplates; registry.templates.ButtonTemplates;
const btnStyle: CSSProperties = { const btnStyle: CSSProperties = {
flex: 1, marginBottom: '0.5em',
paddingLeft: 6,
paddingRight: 6,
fontWeight: 'bold',
}; };
const mainColumnWidthSmall = hasToolbar ? 3 : 4;
const mainColumnWidthMedium = hasToolbar ? 6 : 8;
const mainColumnWidthLarge = hasToolbar ? 12 : 16;
return ( return (
<div className={className}> <div className={className}>
<div className={hasToolbar ? 'col-xs-9' : 'col-xs-12'}>{children}</div> <Grid condensed fullWidth>
{hasToolbar && ( <Column
<div className="col-xs-3 array-item-toolbox"> sm={mainColumnWidthSmall}
<div md={mainColumnWidthMedium}
className="btn-group" lg={mainColumnWidthLarge}
style={{ >
display: 'flex', {children}
justifyContent: 'space-around', </Column>
}} {hasToolbar && (
<Column
sm={4 - mainColumnWidthSmall}
md={8 - mainColumnWidthMedium}
lg={16 - mainColumnWidthLarge}
> >
{(hasMoveUp || hasMoveDown) && ( <div className="array-item-toolbox">
<MoveUpButton <div className="NOT-btn-group">
style={btnStyle} <div>
disabled={disabled || readonly || !hasMoveUp} {(hasMoveUp || hasMoveDown) && (
onClick={onReorderClick(index, index - 1)} <MoveUpButton
uiSchema={uiSchema} style={btnStyle}
registry={registry} disabled={disabled || readonly || !hasMoveUp}
/> onClick={onReorderClick(index, index - 1)}
)} uiSchema={uiSchema}
{(hasMoveUp || hasMoveDown) && ( registry={registry}
<MoveDownButton />
style={btnStyle} )}
disabled={disabled || readonly || !hasMoveDown} </div>
onClick={onReorderClick(index, index + 1)} <div>
uiSchema={uiSchema} {(hasMoveUp || hasMoveDown) && (
registry={registry} <MoveDownButton
/> style={btnStyle}
)} disabled={disabled || readonly || !hasMoveDown}
{hasRemove && ( onClick={onReorderClick(index, index + 1)}
<RemoveButton uiSchema={uiSchema}
style={btnStyle} registry={registry}
disabled={disabled || readonly} />
onClick={onDropIndexClick(index)} )}
uiSchema={uiSchema} </div>
registry={registry} <div>
/> {hasRemove && (
)} <RemoveButton
</div> style={btnStyle}
</div> disabled={disabled || readonly}
)} onClick={onDropIndexClick(index)}
uiSchema={uiSchema}
registry={registry}
/>
)}
</div>
</div>
</div>
</Column>
)}
</Grid>
</div> </div>
); );
} }

View File

@ -1,55 +1,96 @@
import React from 'react'; import React from 'react';
import IconButton, { import {
IconButtonProps as MuiIconButtonProps, FormContextType,
} from '@mui/material/IconButton'; IconButtonProps,
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward'; RJSFSchema,
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'; StrictRJSFSchema,
import RemoveIcon from '@mui/icons-material/Remove'; } from '@rjsf/utils';
import { IconButtonProps } from '@rjsf/utils';
export default function MuiIconButton(props: IconButtonProps) { // @ts-ignore
const { icon, color, uiSchema, ...otherProps } = props; import { Add, TrashCan, ArrowUp, ArrowDown } from '@carbon/icons-react';
export default function IconButton<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: IconButtonProps<T, S, F>) {
const {
iconType = 'default',
icon,
className,
uiSchema,
registry,
...otherProps
} = props;
// icon string optios: plus, remove, arrow-up, arrow-down
let carbonIcon = (
<p>
Add new <Add />
</p>
);
if (icon === 'remove') {
carbonIcon = <TrashCan />;
}
if (icon === 'arrow-up') {
carbonIcon = <ArrowUp />;
}
if (icon === 'arrow-down') {
carbonIcon = <ArrowDown />;
}
return (
<button
type="button"
className={`btn btn-${iconType} ${className}`}
{...otherProps}
>
{carbonIcon}
</button>
);
}
export function MoveDownButton<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: IconButtonProps<T, S, F>) {
return ( return (
<IconButton <IconButton
{...otherProps}
size="small"
color={color as MuiIconButtonProps['color']}
>
{icon}
</IconButton>
);
}
export function MoveDownButton(props: IconButtonProps) {
return (
<MuiIconButton
title="Move down" title="Move down"
className="array-item-move-down"
{...props} {...props}
icon={<ArrowDownwardIcon fontSize="small" />} icon="arrow-down"
/> />
); );
} }
export function MoveUpButton(props: IconButtonProps) { export function MoveUpButton<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: IconButtonProps<T, S, F>) {
return ( return (
<MuiIconButton <IconButton
title="Move up" title="Move up"
className="array-item-move-up"
{...props} {...props}
icon={<ArrowUpwardIcon fontSize="small" />} icon="arrow-up"
/> />
); );
} }
export function RemoveButton(props: IconButtonProps) { export function RemoveButton<
const { iconType, ...otherProps } = props; T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: IconButtonProps<T, S, F>) {
return ( return (
<MuiIconButton <IconButton
title="Remove" title="Remove"
{...otherProps} className="array-item-remove"
color="error" {...props}
icon={ iconType="danger"
<RemoveIcon fontSize={iconType === 'default' ? undefined : 'small'} /> icon="remove"
}
/> />
); );
} }

View File

@ -17,3 +17,7 @@
.rjsf .rjsf-field .rjsf-field { .rjsf .rjsf-field .rjsf-field {
margin-bottom: 2em; margin-bottom: 2em;
} }
.array-item-toolbox {
margin-left: 2em;
}