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

fix(Alert): padding issue when no dismiss button #2853

Merged
merged 26 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
15 changes: 13 additions & 2 deletions packages/gamut/src/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
alertContentProps,
CollapsableContent,
} from './elements';
import { alertVariants, getGridTemplateColumns } from './variants';
import { alertVariants, getAlertRightPadding,getGridTemplateColumns } from './variants';

export type AlertType = keyof typeof alertVariants;
export type AlertPlacements = 'inline' | 'floating';
Expand Down Expand Up @@ -85,10 +85,20 @@ export const Alert: React.FC<AlertProps> = ({
? `max-content minmax(0, 1fr) repeat(1, max-content)`
: getGridTemplateColumns({
cta: ctaExists,
// cta: false,
// onClose: false,
onClose: !!onClose,
truncated,
});
}, [ctaExists, isDesktop, onClose, truncated]);
// }, [/* /, isDesktop, onClose, truncated]);
// }, [ctaExists, isDesktop, /* onClose */, truncated]);
// }, [/* ctaExists */, isDesktop, /* onClose */, truncated]);


const alertRightPadding = useMemo(() => {
return getAlertRightPadding(Boolean(onClose)) ;
}, [onClose])

const tabIndex = hidden ? -1 : undefined;

Expand Down Expand Up @@ -131,6 +141,7 @@ export const Alert: React.FC<AlertProps> = ({
);

const buttonColorMode = isSubtleVariant ? currentColorMode : 'dark';
// onClose = false

const ctaButton = ctaExists && (
<Box
Expand All @@ -151,12 +162,12 @@ export const Alert: React.FC<AlertProps> = ({
);

const AlertWrapper = isSubtleVariant ? AlertBox : AlertBanner;

return (
<AlertWrapper
bg={bg}
placement={placement}
gridTemplateColumns={gridTemplateColumns}
pr={alertRightPadding}
{...props}
>
<Icon size={32} aria-hidden p={8} />
Expand Down
2 changes: 1 addition & 1 deletion packages/gamut/src/Alert/elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const AlertBanner = forwardRef<
>(
(
{
'aria-label': ariaLabel = 'alert box',
'aria-label': ariaLabel = 'alert banner',
'aria-live': ariaLive = 'polite',
role = 'status',
...rest
Expand Down
8 changes: 6 additions & 2 deletions packages/gamut/src/Alert/variants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export const placementVariants = variant({
prop: 'placement',
base: {
alignItems: 'start',
columnGap: [4, 8, , 12],
columnGap: {_: 4, xs: 8, sm: 12},
display: 'grid',
maxWidth: `calc(${breakpoints.md} - 4rem)`,
px: 4,
pl: 4,
width: 1,
},
variants: {
Expand Down Expand Up @@ -80,3 +80,7 @@ export const getGridTemplateColumns = (
const repeatCount = numOfButtons <= 0 ? 1 : numOfButtons;
return `max-content minmax(0, 1fr) repeat(${repeatCount}, max-content)`;
};

export const getAlertRightPadding = (onClose: boolean) => {
return onClose ? 4 : {_: 4, xs: 12, sm: 16} as const
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ALERTS } from './constants';
source: 'gamut',
design: {
type: 'figma',
url: 'https://www.figma.com/file/TemYhRWOavsERWprDzRJCx',
url: 'https://www.figma.com/file/ReGfRNillGABAj5SlITalN/%F0%9F%93%90-Gamut?node-id=30186%3A40359',
},
padded: true,
}}
Expand Down
Loading