Skip to content

Commit

Permalink
fix(plate): fix custom view border (#1479)
Browse files Browse the repository at this point in the history
* feat(plate): fix custom view border
  • Loading branch information
fulcanellee authored Dec 26, 2024
1 parent 138ae13 commit 98cd512
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-schools-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alfalab/core-components-plate': patch
---

Исправлена установка цвета `border` для элемента `view=custom shape=rect`

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 26 additions & 14 deletions packages/plate/src/component.screenshots.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,32 @@ describe(
);

describe(
'Plate | custom view and background',
'Plate | custom view, border and background',
screenshotTesting({
cases: generateTestCases({
componentName: 'Plate',
testStory: false,
knobs: {
view: 'custom',
title: 'Поздравляем, полный успех',
children: 'Вам одобрено. Согласитесь на предложение',
background: 'var(--color-light-decorative-muted-indigo)',
borderColor: 'var(--color-light-decorative-indigo)',
},
wrapperStyles: 'width:500px',
}),
viewport: { width: 1024, height: 160 },
cases: [
[
'sprite',
createSpriteStorybookUrl({
componentName: 'Plate',
knobs: {
view: 'custom',
title: 'Поздравляем, полный успех',
children: 'Вам одобрено. Согласитесь на предложение',
background: 'var(--color-light-decorative-muted-indigo)',
borderColor: 'var(--color-light-decorative-indigo)',
border: [true, false],
rounded: [true, false],
},
size: { width: 400, height: 140 },
}),
],
],
screenshotOpts: {
fullPage: true,
},
viewport: {
width: 1024,
height: 140,
},
}),
);
30 changes: 26 additions & 4 deletions packages/plate/src/components/base-plate/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export const BasePlate = forwardRef<HTMLDivElement, BasePlateProps>(

const rowLimitStyles = rowLimit && commonStyles[`rowLimit${rowLimit}`];

const isCustomView = view === 'custom';

const handleClick = useCallback(
(event: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => {
const clickSimilarKeys = ['Enter', ' '].includes(
Expand Down Expand Up @@ -268,6 +270,27 @@ export const BasePlate = forwardRef<HTMLDivElement, BasePlateProps>(
[onClose],
);

const setCustomViewColors = (): { background: string; borderColor: string } | object => {
if (isCustomView) {
return {
background,
borderColor,
};
}

return {};
};

const setCustomViewRectangleBorderColor = (): { boxShadow: string } | object => {
if (isCustomView && border && !rounded && borderColor) {
return {
boxShadow: `2px 0 0 0 ${borderColor} inset`,
};
}

return {};
};

return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<div
Expand All @@ -279,20 +302,19 @@ export const BasePlate = forwardRef<HTMLDivElement, BasePlateProps>(
[commonStyles.focused]: focused,
[commonStyles.isHidden]: hasCloser && isHidden,
[commonStyles.isFolded]: foldable && folded,

[commonStyles.rounded]: rounded,
[styles.rounded]: rounded,

[commonStyles.rect]: !rounded,
[commonStyles.noBorder]: !border,

[commonStyles.shadow]: shadow,
[styles.shadow]: shadow,
[commonStyles.customBorder]: border && !rounded && isCustomView,
},
className,
)}
style={{
...(view === 'custom' && { background, borderColor }),
...setCustomViewColors(),
...setCustomViewRectangleBorderColor(),
}}
onClick={handleClick}
onKeyDown={handleClick}
Expand Down
4 changes: 4 additions & 0 deletions packages/plate/src/components/base-plate/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
top: var(--gap-0);
left: var(--gap-0);
}

&.customBorder:before {
all: unset;
}
}

.foldable {
Expand Down
18 changes: 0 additions & 18 deletions packages/plate/src/docs/Component.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ export const plate: Story = {
...previewStyles,
}}
>
<style>
{`.custom {
background: rgba(207, 112, 255, 0.1);
box-shadow: 0 0 0 1px rgba(207, 112, 255, 1);
`}
</style>
<Plate
className={view === 'custom' ? 'custom' : undefined}
view={view}
Expand Down Expand Up @@ -123,12 +117,6 @@ export const plate_mobile: Story = {
...previewStyles,
}}
>
<style>
{`.custom {
background: rgba(207, 112, 255, 0.1);
box-shadow: 0 0 0 1px rgba(207, 112, 255, 1);
`}
</style>
<PlateMobile
className={view === 'custom' ? 'custom' : undefined}
view={view}
Expand Down Expand Up @@ -196,12 +184,6 @@ export const plate_desktop: Story = {
...previewStyles,
}}
>
<style>
{`.custom {
background: rgba(207, 112, 255, 0.1);
box-shadow: 0 0 0 1px rgba(207, 112, 255, 1);
`}
</style>
<PlateDesktop
className={view === 'custom' ? 'custom' : undefined}
view={view}
Expand Down

0 comments on commit 98cd512

Please sign in to comment.