Skip to content

Commit

Permalink
feat(TotalLayout): TotalLayoutHeader new props.
Browse files Browse the repository at this point in the history
fix(Colors): Loader and Notifications buttons colors.
  • Loading branch information
johan-fx committed Dec 16, 2023
1 parent 75401ae commit 4629e79
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"[javascript]": {
"editor.codeActionsOnSave": {
"source.organizeImports": false,
"source.fixAll": true,
"source.organizeImports": "never",
"source.fixAll": "explicit"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
38 changes: 19 additions & 19 deletions packages/components/src/feedback/Alert/Alert.styles.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
import { createStyles } from '@mantine/styles';
import { pxToRem, getPaddings, getFontExpressive, getFontProductive } from '../../theme.mixins';

const getColor = (theme, severity) => {
return {
const getColor = (theme, severity) =>
({
success: {
background: `${theme.colors.fatic02v0} !important`,
background: `#E4F4E6 !important`,
'.mantine-Alert-icon, .mantine-Alert-action': {
color: theme.colors.fatic02,
color: '#368442',
},
},
warning: {
background: `${theme.colors.fatic03v0} !important`,
background: `#FEF3E1 !important`,
'.mantine-Alert-icon, .mantine-Alert-action': {
color: theme.colors.fatic03,
color: '#BA7609',
},
},
info: {
background: `${theme.colors.fatic04v0} !important`,
background: `#F1FFBD !important`,
'.mantine-Alert-icon, .mantine-Alert-action': {
color: theme.colors.fatic04,
color: '#98C200',
},
},
error: {
background: `${theme.colors.fatic01v0} !important`,
background: `#F7DEDE !important`,
'.mantine-Alert-icon, .mantine-Alert-action': {
color: theme.colors.fatic01,
color: '#B52A2A',
},
},
}[severity];
};
})[severity];

export const AlertStyles = createStyles((theme, { variant, severity }) => {
const AlertStyles = createStyles((theme, { variant, severity }) => {
const alertTheme = theme;
return {
root: {
...getFontExpressive(theme.fontSizes['2']),
...getColor(theme, severity),
display: 'flex',
alignItems: 'center',
borderRadius: variant === 'block' ? pxToRem(2) : pxToRem(0),
padding:
variant === 'block'
? `${pxToRem(8)} ${pxToRem(16)} ${pxToRem(12)} ${pxToRem(24)}`
: `${pxToRem(8)} ${pxToRem(16)} ${pxToRem(12)} ${pxToRem(24)}`,
padding: `${pxToRem(8)} ${pxToRem(16)} ${pxToRem(12)} ${pxToRem(24)}`,
},
message: {},
wrapper: {
Expand All @@ -60,14 +57,15 @@ export const AlertStyles = createStyles((theme, { variant, severity }) => {
gap: theme.spacing['2'],
},
title: {
...getFontExpressive(theme.fontSizes['2'], 600),
...getFontExpressive(theme.fontSizes['2'], 500),
color: '#4D5358',
marginRight: pxToRem(15),
lineHeight: 1.2,
paddingTop: theme.spacing[2],
paddingBottom: theme.spacing[2],
},
content: {
...getFontProductive(theme.fontSizes['2'], 400),
...getFontProductive(theme.fontSizes['2'], 500),
flex: '1 1 100%',
marginRight: variant === 'block' ? pxToRem(24) : pxToRem(28),
lineHeight: 1.2,
Expand All @@ -93,3 +91,5 @@ export const AlertStyles = createStyles((theme, { variant, severity }) => {
},
};
});

export { AlertStyles };
8 changes: 6 additions & 2 deletions packages/components/src/feedback/Loader/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isString } from 'lodash';
import { Loader as MantineLoader } from '@mantine/core';
import { ContextContainer, CONTEXT_CONTAINER_PROP_TYPES } from '../../layout';
import { Text } from '../../typography';
import { LoaderStyles } from './Loader.styles';

export const LOADER_LABEL_POSITIONS = ['right', 'bottom'];

Expand All @@ -22,20 +23,23 @@ export const LOADER_PROP_TYPES = {
labelPosition: PropTypes.oneOf(LOADER_LABEL_POSITIONS),
/** Controls if Loader uses aria role */
useAria: PropTypes.bool,
className: PropTypes.string,
};

const Loader = ({ padded, label, labelPosition, useAria, ...props }) => {
const direction = useMemo(() => (labelPosition === 'right' ? 'row' : 'column'), [labelPosition]);
const { classes, cx } = LoaderStyles({}, { name: 'Loader' });

return (
<ContextContainer
{...props}
className={cx(props.className, classes.root)}
direction={direction}
padded={padded}
alignItems="center"
justifyContent="center"
role={useAria ? 'progressbar' : undefined}
role={useAria ? 'progress' : undefined}
aria-label={useAria ? 'BubblesLoader' : undefined}
{...props}
>
<MantineLoader />
{isString(label) && <Text>{label}</Text>}
Expand Down
11 changes: 9 additions & 2 deletions packages/components/src/feedback/Loader/Loader.styles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { createStyles } from '@mantine/styles';
import { pxToRem, getPaddings, getFontExpressive, getFontProductive } from '../../theme.mixins';
import { getFontExpressive } from '../../theme.mixins';

const LoaderStyles = createStyles((theme) => {
const loaderTheme = theme.other.core;

export const LoaderStyles = createStyles((theme, {}) => {
return {
root: {
...getFontExpressive(theme.fontSizes['2']),
svg: {
stroke: loaderTheme.color.primary['300'],
},
},
};
});

export { LoaderStyles };
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const IMAGE_PREVIEW_INPUT_PROP_TYPES = {
uploadButton: PropTypes.string,
changeImage: PropTypes.string,
}),
value: PropTypes.instanceOf(File),
previewURL: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(File)]),
value: PropTypes.any,
previewURL: PropTypes.oneOfType([PropTypes.string, PropTypes.any]),
previewStyle: PropTypes.object,
control: PropTypes.element,
onChange: PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export {
getPaddings,
getHtmlStyles,
getBoxShadowFromToken,
getFocusDefaultBorder,
} from './theme.mixins';
export { PALETTE } from './theme.constants';
export { COLORS } from './theme.tokens';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const TOTAL_LAYOUT_HEADER_PROP_TYPES = {
formTitlePlaceholder: PropTypes.string,
compact: PropTypes.bool,
icon: PropTypes.element,
onCancel: PropTypes.func,
children: PropTypes.node,
cancelable: PropTypes.bool,
direction: PropTypes.oneOf(['row', 'column']),
};

export const TOTAL_LAYOUT_HEADER_DEFAULT_PROPS = {
title: '',
icon: <Icon />,
formTitlePlaceholder: '',
compact: false,
cancelable: true,
direction: 'column',
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const TotalLayoutHeader = ({
children,
onCancel,
compact = false,
direction = 'column',
cancelable = true,
}) => {
const { watch } = useFormContext();
const formValues = watch();
const { classes } = TotalLayoutHeaderStyles({ compact, children });
const { classes } = TotalLayoutHeaderStyles({ compact, direction, children });

return (
<Stack fullWidth fullHeight className={classes.headerContainer} direction="column">
Expand Down Expand Up @@ -54,14 +56,18 @@ const TotalLayoutHeader = ({
</Stack>
{/* CANCEL BUTTON */}
<Stack alingItems="center">
<Button variant="link" type="button" leftIcon={<CrossIcon />} onClick={onCancel}>
Cancelar
</Button>
{/* CHILDREN */}
{!!children && direction === 'row' && children}
{cancelable && (
<Button variant="link" type="button" leftIcon={<CrossIcon />} onClick={onCancel}>
Cancelar
</Button>
)}
</Stack>
</Stack>

{/* CHILDREN */}
{children && (
{!!children && direction === 'column' && (
<Stack style={{ maxHeight: '40px', minHeight: '40px', marginTop: '12px' }}>
{children}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { TotalLayoutHeader } from './TotalLayoutHeader';
import { TOTAL_LAYOUT_HEADER_DEFAULT_PROPS } from './TotalLayoutHeader.constants';
import mdx from './TotalLayoutHeader.mdx';
import { ContextContainer } from '../../ContextContainer';
import { Stack } from '../../Stack';
import { Button } from '../../../form/Button';

export default {
title: 'Atoms/Layout/TotalLayout/TotalLayoutHeader',
Expand All @@ -18,12 +20,25 @@ export default {
// url: 'https://www.figma.com/file/kcSXz3QZFByFDTumNgzPpV/?node-id=2962%3A31342',
},
},
argTypes: {},
argTypes: {
direction: {
control: 'select',
options: ['row', 'column'],
},
},
};

const MockComponent = () => (
<div>MOCK COMPONENT CHILD OF TOTAL LAYOUT HEADER - RESPECTS PADDING</div>
);

const OtherMockComponent = () => (
<Stack>
<Button variant="link">Button A</Button>
<Button variant="link">Button B</Button>
<Button variant="link">Button C</Button>
</Stack>
);
const Template = (props) => {
const formMethods = useForm();

Expand All @@ -32,12 +47,18 @@ const Template = (props) => {
<ContextContainer
id="container-for-storybook"
divided
padded
style={{ height: '100vh', width: '100wh', margin: '-16px', backgroundColor: '#f8f9fb' }}
>
<TotalLayoutHeader {...props} />

<TotalLayoutHeader {...props}>
<MockComponent />
</TotalLayoutHeader>

<TotalLayoutHeader {...props} direction="row">
<OtherMockComponent />
</TotalLayoutHeader>
</ContextContainer>
</FormProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import { createStyles } from '@mantine/styles';

const TotalLayoutHeaderStyles = createStyles((theme, { children, compact }) => ({
root: {},
headerContainer: {
padding: `${!children ? '16px' : '12px'} 24px`,
minHeight: !children ? '72px' : '120px',
maxHeight: !children ? '72px' : '120px',
backgroundColor: 'white',
},
header: { height: '40px', maxHeight: '40px' },
headerTools: { maxHeight: '40px', minHeight: '40px', marginTop: '12px' },
iconContainer: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '1.4rem',
width: '32px',
height: '32px',
textAlign: 'center',
marginRight: '8px',
},
headerTitle: { fontSize: '18px', fontWeight: 600, lineHeight: '24px' },
headerSubtitle: {
fontSize: '18px',
fontWeight: 400,
lineHeight: '24px',
marginLeft: !compact && '40px',
},
}));
const TotalLayoutHeaderStyles = createStyles((theme, { children, direction, compact }) => {
const expandedHeader = direction === 'column' && children;
return {
root: {},
headerContainer: {
padding: `${!expandedHeader ? '16px' : '12px'} 24px`,
minHeight: !expandedHeader ? '72px' : '120px',
maxHeight: !expandedHeader ? '72px' : '120px',
backgroundColor: 'white',
},
header: { height: '40px', maxHeight: '40px' },
headerTools: { maxHeight: '40px', minHeight: '40px', marginTop: '12px' },
iconContainer: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '1.4rem',
width: '32px',
height: '32px',
textAlign: 'center',
marginRight: '8px',
},
headerTitle: { fontSize: '18px', fontWeight: 600, lineHeight: '24px' },
headerSubtitle: {
fontSize: '18px',
fontWeight: 400,
lineHeight: '24px',
marginLeft: !compact && '40px',
},
};
});

export { TotalLayoutHeaderStyles };
15 changes: 12 additions & 3 deletions packages/components/src/navigation/Anchor/Anchor.styles.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { createStyles } from '@mantine/styles';

export const AnchorStyles = createStyles((theme, {}) => {
const AnchorStyles = createStyles((theme) => {
const buttonTheme = theme.other.button;
return {
root: {
textDecoration: 'underline',
color: theme.colors.interactive01,
textDecoration: buttonTheme.textDecoration.underLine,
color: buttonTheme.content.color.secondary.default,
cursor: 'pointer',
'&:hover': {
color: buttonTheme.content.color.primary.default,
},
'&:active': {
color: buttonTheme.content.color.secondary.pressed,
},
},
};
});

export { AnchorStyles };
Loading

0 comments on commit 4629e79

Please sign in to comment.