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

Evol/drawer #4

Open
wants to merge 22 commits into
base: evol/lists-and-filters
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e33d2c5
implement generic drawer and user edit form
lucas-amiaud Feb 4, 2022
09aad91
rearrange project components
lucas-amiaud Feb 4, 2022
e8b489c
merge lists and filters
lucas-amiaud Feb 4, 2022
9e81c71
merge lists and filters
lucas-amiaud Feb 4, 2022
41e7fcb
merge list and filters
lucas-amiaud Feb 4, 2022
573d116
merge list and filters
lucas-amiaud Feb 7, 2022
9e8603b
a bit of responsive
lucas-amiaud Feb 7, 2022
814657f
merge lists and filters
lucas-amiaud Feb 18, 2022
3217a2a
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Feb 18, 2022
e06ad10
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Mar 21, 2022
3b9a62f
pr feedback resolution
lucas-amiaud Mar 24, 2022
3c210d4
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Apr 11, 2022
9104597
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Apr 12, 2022
a464d77
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Apr 13, 2022
25ee52d
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Apr 27, 2022
143bbe0
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Apr 29, 2022
7528548
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud May 3, 2022
f133c5f
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud May 25, 2022
bc4adc8
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Jun 9, 2022
2589eb9
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Jun 14, 2022
2d6b1c1
fix eslint
lucas-amiaud Jun 14, 2022
9721d99
Merge branch 'evol/lists-and-filters' into evol/drawer
lucas-amiaud Oct 17, 2023
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
2 changes: 1 addition & 1 deletion templates/admin/assets/scss/_material-override.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use "variables" as *;
@use "mixins" as *;

.app {
.app, .MuiModal-root {

/* BUTTONS */
.MuiButton-root {
Expand Down
85 changes: 85 additions & 0 deletions templates/admin/assets/scss/components/_drawers.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
@use 'assets/scss/variables' as *;

.drawer {
display: flex;
flex-direction: column;
height: 100%;

&--20 {
.MuiDrawer-paper {
width: 20%;
}
}

&--40 {
.MuiDrawer-paper {
width: 40%;
}
}

&--50 {
.MuiDrawer-paper {
width: 50%;
}
}

&--60 {
.MuiDrawer-paper {
width: 60%;
}
}

&--80 {
.MuiDrawer-paper {
width: 80%;
}
}

&--80, &--full {
.MuiDrawer-paper {
width: 100%;
}
}
}

.drawer-header {
height: 6%;
display: flex;
padding: $spacer-6 + $spacer-2;
position: relative;
justify-content: center;
background: rgba($secondary-color, 10%);

button {
position: absolute;
top: 50%;
left: $spacer-5;
transform: translateY(-50%);

span {
margin-right: $spacer-3;
}
}

.drawer-title-container {
position: absolute;
height: 100%;
top: 50%;
left: 40%;
display: flex;
align-items: center;
transform: translateY(-50%);

h1 {
color: $secondary-color;
font-size: $font-size-large;
text-align: center;
}
}
}

.drawer-content {
height: 100%;
overflow: auto;
padding: $spacer-6 $spacer-8;
}
1 change: 1 addition & 0 deletions templates/admin/assets/scss/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@forward 'sort-menu';
@forward 'filter-menu';
@forward 'search-bar';
@forward 'drawers';
15 changes: 13 additions & 2 deletions templates/admin/assets/scss/components/_popin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@
align-items: center;

.popin-container {
background-color: #ffffff;
box-shadow: 0 3px 5px 1px rgba(#000000, .25);
background-color: #fff;
box-shadow: 0 3px 5px 1px rgba(#000, .25);
border-radius: $border-radius-3;
padding: $spacer-6;
max-width: 600px;

Choose a reason for hiding this comment

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

Pourquoi ça ?

max-height: 100%;
overflow: auto;

.popin-title {
color: $secondary-color;
font-size: $font-size-large;
}

.popin-message {
margin: $spacer-6 0;
white-space: pre-wrap;
}
}
}
2 changes: 1 addition & 1 deletion templates/admin/assets/scss/layouts/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
@forward 'layout';
@forward 'navigation';
@forward 'columns';
@forward 'lists';
@forward 'lists';
9 changes: 9 additions & 0 deletions templates/admin/assets/scss/modules/_variables.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@use "../variables" as *;

:export{

Choose a reason for hiding this comment

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

Je ne comprends pas bien à quoi sert ce fichier

widthSmallScreen: $width-small-screen-px;
widthMediumScreen: $width-medium-screen-px;

primaryColor: $primary-color;
secondaryColor: $secondary-color;
}
9 changes: 9 additions & 0 deletions templates/admin/src/components/theme/AdminTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {
ActionContainerProps,
ActionLinkProps,
} from '../../lib/plume-admin-theme/action/ActionProps';
import {
DrawerTypeProps, UncontrolledDrawerTypeProps,
} from '../../lib/plume-admin-theme/drawer/DrawerProps';
import {
FormFieldProps,
} from '../../lib/plume-admin-theme/form/FormFieldProps';
Expand Down Expand Up @@ -34,6 +37,8 @@ import {
PopinProps,
} from '../../lib/plume-admin-theme/popin/PopinProps';
import { ActionButton, ActionLink, ActionsContainer } from './action/Actions';
import Drawer from './drawer/Drawer';
import UncontrolledDrawer from './drawer/UncontrolledDrawer';
import InputSelect from './form/fields/InputSelect';
import InputText from './form/fields/InputText';
import FormField from './form/FormField';
Expand Down Expand Up @@ -89,6 +94,10 @@ export default class AdminTheme implements PlumeAdminTheme {

popinCloseWithoutSaving: (props: PopinCloseWithoutSavingProps) => JSX.Element | null = PopinCloseWithoutSaving;

drawer: (props: DrawerTypeProps) => JSX.Element = Drawer;

uncontrolledDrawer: (props: UncontrolledDrawerTypeProps) => JSX.Element = UncontrolledDrawer;

formField: (props: FormFieldProps) => JSX.Element = FormField;

inputText: (props: InputTextProps) => JSX.Element = InputText;
Expand Down
64 changes: 64 additions & 0 deletions templates/admin/src/components/theme/drawer/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Drawer as MaterialDrawer, Icon } from '@mui/material';
import React from 'react';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

Choose a reason for hiding this comment

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

Pourquoi ts ignore ? Normalement c'est interdit d'utiliser ça d'ailleurs

import cssVariables from '../../../../assets/scss/modules/_variables.module.scss';
import useMessages from '../../../i18n/hooks/messagesHook';
import ActionStyle from '../../../lib/plume-admin-theme/action/ActionStyle';
import {
DrawerTypeProps,
} from '../../../lib/plume-admin-theme/drawer/DrawerProps';
import { ActionButton } from '../action/Actions';

export default function Drawer(

Choose a reason for hiding this comment

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

Antoine LL Tu penses qu'on peut reprendre des choses du slider de la VEL ?

{
title, children, open, close, size, fullScreen, sizedByWidth, className,
}: DrawerTypeProps) {
const { messages } = useMessages();
const { widthSmallScreen, widthMediumScreen } = cssVariables;

// Returns width percentage of drawer
const drawerSize = () => {
const defaultSize: number = 40;
const largeSize: number = 60;
if (sizedByWidth) {
const width: number = window.innerWidth;
if (width < widthSmallScreen) {
return 'full';
}

return width < widthMediumScreen ? largeSize : defaultSize;
}

return size || defaultSize;
};

return (
<MaterialDrawer
anchor="right"
open={open}
onClose={close}
className={`drawer${className || ''} ${fullScreen ? ' drawer--full-screen' : ''} drawer--${drawerSize()}`}
>
<div className={`drawer ${fullScreen ? 'drawer--full' : ''}`}>
<div className="drawer-header">
<div className="drawer-button-container">
<ActionButton
onClick={close}
style={ActionStyle.SECONDARY}
cssClasses={ActionStyle.SECONDARY}
>
<Icon>chevron_left</Icon>
{messages.action.close}
</ActionButton>
</div>
<div className="drawer-title-container">
<h1>{title || ''}</h1>
</div>
<div />
</div>
<div className="drawer-content">{children}</div>
</div>
</MaterialDrawer>
);
}
52 changes: 52 additions & 0 deletions templates/admin/src/components/theme/drawer/UncontrolledDrawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { getGlobalInstance } from 'plume-ts-di';
import React, { useEffect } from 'react';
import {
UncontrolledDrawerTypeProps,
} from '../../../lib/plume-admin-theme/drawer/DrawerProps';
import PlumeAdminTheme from '../../../lib/plume-admin-theme/PlumeAdminTheme';
import useToggle from '../../../lib/react-hook-toggle/ReactHookToggle';

/**
* When a drawer is a all page, there is no state to control its opening / closing

Choose a reason for hiding this comment

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

is a whole page* ?
pas compris pourquoi il y aurait pas de state ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

y a pas de state dans le parent pour controler l'ouverture / la fermeture. Donc c'est lui même qui gère son état d'ouverture / fermeture et le parent ne se charge de rien

Choose a reason for hiding this comment

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

Dans ce cas, le composant est mal nommé, c'est plutôt fullPageDrawer ou quelque chose dans le genre

*/
function UncontrolledDrawer(
{
title,
onClose,
children,
size,
sizedByWidth,
fullScreen,
className,
}: UncontrolledDrawerTypeProps,
) {
const theme: PlumeAdminTheme = getGlobalInstance(PlumeAdminTheme);
const [isDrawerOpened, toggleDrawer] = useToggle(false);

useEffect(() => {
if (!isDrawerOpened) {
setTimeout(toggleDrawer, 0);
}
}, [children]);

const uncontrolledClose = () => {
toggleDrawer();
setTimeout(onClose, 300);
};

return (
<theme.drawer
title={title}
open={isDrawerOpened}
close={uncontrolledClose}
size={size}
sizedByWidth={sizedByWidth}
fullScreen={fullScreen}
className={className}
>
{children}
</theme.drawer>
);
}

export default (UncontrolledDrawer);
58 changes: 43 additions & 15 deletions templates/admin/src/components/theme/form/fields/InputSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { MenuItem, TextField } from '@mui/material';
import React from 'react';
import { SelectElement } from 'react-hook-form-mui';
import { useController } from 'react-hook-form';
import {
InputSelectProps,
SelectOptionProps,
} from '../../../../lib/plume-admin-theme/form/FormInputProps';

export default function InputSelect(
Expand All @@ -20,24 +22,50 @@ export default function InputSelect(
}: InputSelectProps) {
const fieldId: string = useNameAsId ? (name ?? 'undefined_input_name') : (id ?? 'undefined_input_id');

const { field } = useController({
name: fieldId,
control,
rules: { required: required ?? false },
defaultValue: defaultValue || '',
});

const onBlurCombined = (value: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>) => {
field.onBlur();
if (onBlur) {
onBlur(value);
}
};

const onChangeField = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
field.onChange(event);
if (onChange) {
onChange(event.target.value);
}
};

return (
<SelectElement
<TextField

Choose a reason for hiding this comment

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

Pourquoi TextField et pas Select ?

className={required ? 'field-required' : ''}
control={control}
select
label={label}
name={fieldId}
name={name}
variant="filled"
id={fieldId}
options={options}
valueKey="value"
labelKey="label"
defaultValue={defaultValue}
required={required}
id={useNameAsId ? name : id}
disabled={disabled ?? false}
onBlur={onBlur}
onChange={onChange}
// disable FormHelper
parseError={() => ''}
/>
value={field.value}
inputRef={field.ref}
onBlur={onBlurCombined}
onChange={onChangeField}
>
{
React.Children.toArray(
options?.map((option: SelectOptionProps) => (
<MenuItem key={`${option.label}-${option.value}`} value={option.value}>
{option.label}
</MenuItem>
)),
)
}
</TextField>
);
}
Loading