diff --git a/.storybook/public/global.css b/.storybook/public/global.css index b31107e08a..ec09bbf3e8 100644 --- a/.storybook/public/global.css +++ b/.storybook/public/global.css @@ -862,3 +862,7 @@ table.docblock-argstable tbody.docblock-argstable-body td div:only-child span { border-color: var(--color-light-border-secondary); background: var(--color-light-bg-secondary); } + +.plateGlobal { + --plate-background: url('./images/docs-background.png'); +} diff --git a/.storybook/public/images/docs-background.png b/.storybook/public/images/docs-background.png new file mode 100644 index 0000000000..7d0e315af9 Binary files /dev/null and b/.storybook/public/images/docs-background.png differ diff --git a/packages/alert/src/Component.tsx b/packages/alert/src/Component.tsx index 753d0773f1..adad7919db 100644 --- a/packages/alert/src/Component.tsx +++ b/packages/alert/src/Component.tsx @@ -10,9 +10,9 @@ export type AlertProps = Omit = ({ className, title, ...restProps }) => ( {title} : null} + rounded={false} + limitContentWidth={false} {...restProps} /> ); diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-0-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-0-snap.png index 0464bf88df..29ca95bb5b 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-0-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-0-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b50d3325adecc9d2e688d2255ef4120bb096f706912e21e344ae155e85734b1b -size 4117 +oid sha256:1d9e400838dcc3962b2b836bce4138cfc675c51f6f757720beb860736ab29d3f +size 4080 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-1-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-1-snap.png index c41dfb7440..62de1a13ba 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-1-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-1-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a6c5e82f9ea602b14bfcb78ccafca7968d8c409fcc6be00ec1e718c5bbcfb868 -size 4124 +oid sha256:8e0c621f3cd93c1f3aaeca89336f6f9dd33444babe020f65ccac65f803b25021 +size 4086 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-2-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-2-snap.png index 2a7ed445dc..3cf30c66be 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-2-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-2-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:06cc0aba06e0c2845f7e75caeca4bbbb48a452507782bb08a8864a8cc5332df8 -size 4119 +oid sha256:8dcb4eea7c64f65213e67028e43116c4263dc8720b537386ee9c82f74640543c +size 4078 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-3-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-3-snap.png index 3c2851618f..c38ceebfc3 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-3-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-views-view-3-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0e5d9a528b23922228123aa11f98d8a734d716a5c3407bea02a2fe4747522586 -size 4106 +oid sha256:51eb6da85dce2f1f80bc5afe1d793fd1d5742c009e8b49cd435082300dbfc6ad +size 4068 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-0-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-0-snap.png index a024e64dec..e4eb93e256 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-0-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-0-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1eb46afad00441fd61f73559b4cac66543ee76dd29aeb132d78f3ae6582e67c2 -size 7922 +oid sha256:9c13260291805e4e2f8d8db75c639e67e8388592e799e838ac0305a492469cf1 +size 7782 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-1-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-1-snap.png index 65365bebad..fcdd9d9ace 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-1-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-with-buttons-buttons-0-title-1-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f7851674d0c0a44a9e4a861000ff5b4b8bbc894d3ed144e669d5558a14529ec4 -size 7394 +oid sha256:36cc0aa4ef2a942f71ebb71ae5d763da2320ee5f7506ef4392d3535f530dd63a +size 7249 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-0-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-0-snap.png index a927786327..d051e7b8aa 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-0-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-0-snap.png @@ -1,3 +1,4 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a9330ef5207d4f92255f62f8b42dc4a74b100a9bcd3f41f447ea42d453d5e366 -size 4893 + +oid sha256:ccb0bcbfc73f8a0fbaff6ae5c6c90f4a97b04a34066812c803c25990c97d3865 +size 4809 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-1-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-1-snap.png index c2d0514339..476cea5e87 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-1-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-0-has-closer-1-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:806de7733a75f7a4b8b6a2cb6026774ee065f6a54cbd238a094644d323203b14 -size 4657 +oid sha256:b0ddb089d8c860f63315bf9d851ada7702bb706e887b3be27034c1bbce44b1e2 +size 4617 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-0-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-0-snap.png index 08456c050f..dfb4ae7dcd 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-0-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-0-snap.png @@ -1,3 +1,4 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:99391c56393940bf8f4219250d961483950923f7ab543013e6378726b1b359c8 -size 4375 + +oid sha256:bf626fb6e13e3e64fce2578ffcf431cd8f809f39d6ff09f5c5cfe43a25e68f66 +size 4331 diff --git a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-1-snap.png b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-1-snap.png index 0464bf88df..29ca95bb5b 100644 --- a/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-1-snap.png +++ b/packages/alert/src/__image_snapshots__/alert-screenshots-with-title-and-closer-title-1-has-closer-1-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b50d3325adecc9d2e688d2255ef4120bb096f706912e21e344ae155e85734b1b -size 4117 +oid sha256:1d9e400838dcc3962b2b836bce4138cfc675c51f6f757720beb860736ab29d3f +size 4080 diff --git a/packages/alert/src/index.module.css b/packages/alert/src/index.module.css index e04161ca63..29e307b82d 100644 --- a/packages/alert/src/index.module.css +++ b/packages/alert/src/index.module.css @@ -1,25 +1,9 @@ @import '../../themes/src/default.css'; .component { - border-radius: var(--border-radius-xs) 0 0 var(--border-radius-xs); - border-top: 0; - border-right: 0; - border-bottom: 0; - border-left-width: 2px; - padding-top: var(--gap-s); - padding-bottom: var(--gap-s); - padding-right: var(--gap-s); min-height: 48px; } -.buttons { - margin-top: var(--gap-m); -} - .title { @mixin accent_primary_medium; } - -.content { - max-width: none; -} diff --git a/packages/plate/src/Component.test.tsx b/packages/plate/src/Component.test.tsx index 735cefe389..2d9ac857d1 100644 --- a/packages/plate/src/Component.test.tsx +++ b/packages/plate/src/Component.test.tsx @@ -34,7 +34,7 @@ describe('Plate', () => { expect(getByTestId(dataTestId).tagName).toBe('DIV'); }); - it('should render buttons size=xs, first view=outlined, others view=link', () => { + it('should render buttons size=xxs, first view=secondary, others view=link', () => { const { queryByTestId } = render( { expect(queryByTestId('button-2')).toBeInTheDocument(); expect(queryByTestId('button-3')).toBeInTheDocument(); - expect(queryByTestId('button-1')).toHaveClass('xs'); - expect(queryByTestId('button-2')).toHaveClass('xs'); - expect(queryByTestId('button-3')).toHaveClass('xs'); + expect(queryByTestId('button-1')).toHaveClass('xxs'); + expect(queryByTestId('button-2')).toHaveClass('xxs'); + expect(queryByTestId('button-3')).toHaveClass('xxs'); - expect(queryByTestId('button-1')).toHaveClass('outlined'); + expect(queryByTestId('button-1')).toHaveClass('secondary'); expect(queryByTestId('button-2')).toHaveClass('link'); expect(queryByTestId('button-3')).toHaveClass('link'); }); @@ -61,16 +61,18 @@ describe('Plate', () => { describe('Classes tests', () => { it('should set `className` class', () => { const className = 'test-class'; - const { container } = render(); + const dataTestId = 'test-id'; + const { getByTestId } = render(); - expect(container.firstElementChild).toHaveClass(className); + expect(getByTestId(dataTestId)).toHaveClass(className); }); it('should set `positive` class if `view` prop is `positive`', () => { const view = 'positive'; - const { container } = render(); + const dataTestId = 'test-id'; + const { getByTestId } = render(); - expect(container.firstElementChild).toHaveClass(view); + expect(getByTestId(dataTestId)).toHaveClass(view); }); }); diff --git a/packages/plate/src/Component.tsx b/packages/plate/src/Component.tsx index 23a60258c6..3d01d30a3f 100644 --- a/packages/plate/src/Component.tsx +++ b/packages/plate/src/Component.tsx @@ -14,6 +14,7 @@ import { useFocus } from '@alfalab/hooks'; import { Button, ComponentProps as ButtonProps } from '@alfalab/core-components-button'; import styles from './index.module.css'; +import { ButtonList } from './components/button-list/component'; export type PlateProps = { /** @@ -41,6 +42,31 @@ export type PlateProps = { */ leftAddons?: ReactNode; + /** + * Слот для субаддонов (слева от крестика) + */ + subAddons?: ReactNode | Array>; + + /** + * Включить/выключить скругление + */ + rounded?: boolean; + + /** + * Включить/Выключить обводку + */ + border?: boolean; + + /** + * Включить/выключить тени + */ + shadow?: boolean; + + /** + * Включить/выключить ограничение максимальной ширины контента в 560px + */ + limitContentWidth?: boolean; + /** * Дочерние элементы */ @@ -51,10 +77,15 @@ export type PlateProps = { */ title?: ReactNode; + /** + * Вид заголовка + */ + titleView?: 'bold' | 'light'; + /** * Вид компонента */ - view?: 'common' | 'negative' | 'positive' | 'attention'; + view?: 'common' | 'negative' | 'positive' | 'attention' | 'custom'; /** * Набор действий @@ -76,6 +107,11 @@ export type PlateProps = { */ contentClassName?: string; + /** + * Дополнительный класс для субаддонов + */ + subAddonsClassName?: string; + /** * Обработчик клика по плашке */ @@ -100,6 +136,7 @@ export type PlateProps = { dataTestId?: string; }; +/* eslint-disable complexity */ export const Plate = forwardRef( ( { @@ -107,14 +144,21 @@ export const Plate = forwardRef( foldable: foldableProp = false, folded: foldedProp, defaultFolded = true, + rounded = true, + limitContentWidth = true, leftAddons, + subAddons, children, buttons, title, + titleView = 'bold', view = 'common', + border = view !== 'custom', + shadow = view === 'custom', className, buttonsClassName, contentClassName, + subAddonsClassName, dataTestId, onClick, onClose, @@ -124,6 +168,7 @@ export const Plate = forwardRef( ) => { const plateRef = useRef(null); const contentRef = useRef(null); + const subAddonsRef = useRef(null); const [focused] = useFocus(plateRef, 'keyboard'); @@ -137,8 +182,8 @@ export const Plate = forwardRef( const hasButtons = !!buttons && typeof buttons !== 'boolean'; const hasContent = children || hasButtons; - - const buttonsIsArray = Array.isArray(buttons) && buttons.length > 0; + const hasSubAddons = !!subAddons && typeof subAddons !== 'boolean'; + const hasAnyAddons = leftAddons || subAddons || foldable || hasCloser; const handleClick = useCallback( (event: React.MouseEvent | React.KeyboardEvent) => { @@ -148,6 +193,9 @@ export const Plate = forwardRef( const eventInsideContent = contentRef.current && contentRef.current.contains(target); + const eventInsideSubAddons = + subAddonsRef.current && subAddonsRef.current.contains(target); + const clickSimilarKeys = ['Enter', ' '].includes( (event as React.KeyboardEvent).key, ); @@ -155,6 +203,7 @@ export const Plate = forwardRef( const shouldChangeIsFolded = eventInsideComponent && !eventInsideContent && + !eventInsideSubAddons && (event.type === 'click' || clickSimilarKeys); if (foldable && shouldChangeIsFolded) { @@ -185,94 +234,110 @@ export const Plate = forwardRef( [onClose], ); - const renderButtons = () => { - if (buttonsIsArray) { - return ( -
- {(buttons as Array>).map((button, index) => - button - ? React.cloneElement(button, { - // eslint-disable-next-line react/no-array-index-key - key: index, - size: 'xs', - view: index === 0 ? 'outlined' : 'link', - className: cn(button.props.className, styles.button), - }) - : null, - )} -
- ); - } - - return
{buttons}
; - }; - return ( - // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
-
- {leftAddons &&
{leftAddons}
} -
- {title &&
{title}
} - {hasContent && ( -
-
- {children} - {hasButtons ? renderButtons() : null} + {/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */} +
+
+ {leftAddons &&
{leftAddons}
} +
+ {title &&
{title}
} + {hasContent && ( +
+ {children && ( +
{children}
+ )} + + {hasButtons && ( +
+ +
+ )}
+ )} +
+ + {hasSubAddons && ( +
+
)} -
- {foldable && ( -
- )} + {foldable && ( +
+
+
+ )} - {hasCloser && !foldable && ( -
+ )} +
); }, ); +/* eslint-enable complexity */ /** * Для отображения в сторибуке diff --git a/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-0-snap.png b/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-0-snap.png index 21a14e5d57..aa1608d900 100644 --- a/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-0-snap.png +++ b/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-0-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0d9c912d1b5cd0d62ed59b3c254015a89e530fb873968ec9cbd0204f8f2fc22a -size 11105 +oid sha256:80849729262475f8e6d4b013126c3b5fdc02e8b1d93cbeb5524014c0ffc22ede +size 11090 diff --git a/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-1-snap.png b/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-1-snap.png index 8ccc5a3ae8..09d2b7094b 100644 --- a/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-1-snap.png +++ b/packages/plate/src/__image_snapshots__/plate-buttons-addons-left-addons-1-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:83f937d803a3216bec48f03df4f72c9b52055cf65f162b8ee2d48c8fa9023186 -size 11546 +oid sha256:85a29c8304fe78bc3cdb9a70e44ba5588ae4c6bc18cb6a647cea5ca9d2292167 +size 11536 diff --git a/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-0-snap.png b/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-0-snap.png index 8ccc5a3ae8..09d2b7094b 100644 --- a/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-0-snap.png +++ b/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-0-snap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:83f937d803a3216bec48f03df4f72c9b52055cf65f162b8ee2d48c8fa9023186 -size 11546 +oid sha256:85a29c8304fe78bc3cdb9a70e44ba5588ae4c6bc18cb6a647cea5ca9d2292167 +size 11536 diff --git a/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-1-snap.png b/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-1-snap.png index ba70b47cee..66631296ac 100644 --- a/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-1-snap.png +++ b/packages/plate/src/__image_snapshots__/plate-foldable-with-buttons-addons-foldable-1-snap.png @@ -1,3 +1,4 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1e72944851ed87ff84558d4cf894d256e3ca0ef5b4ab1342a33b109639831385 -size 5880 + +oid sha256:f815082f51657b1bb83989a57c7b3d0527eea1a20dc528a57d8a886b7209f68b +size 5996 \ No newline at end of file diff --git a/packages/plate/src/__image_snapshots__/plate-main-props-sprite-snap.png b/packages/plate/src/__image_snapshots__/plate-main-props-sprite-snap.png index 92b7445c5e..f499137d07 100644 --- a/packages/plate/src/__image_snapshots__/plate-main-props-sprite-snap.png +++ b/packages/plate/src/__image_snapshots__/plate-main-props-sprite-snap.png @@ -1,3 +1,4 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b42a905ebc69df6013a13e574e17b7668e4295d51545956f5f500174c8144e12 -size 179185 + +oid sha256:d6ebe3cf81c84438f5cc554a6ab3d54b19da49a68eff40399ff244aab54932b2 +size 181390 diff --git a/packages/plate/src/__snapshots__/Component.test.tsx.snap b/packages/plate/src/__snapshots__/Component.test.tsx.snap index 180e209862..7a65c70204 100644 --- a/packages/plate/src/__snapshots__/Component.test.tsx.snap +++ b/packages/plate/src/__snapshots__/Component.test.tsx.snap @@ -3,46 +3,50 @@ exports[`Plate Snapshots tests should match snapshot 1`] = `