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(Pageheader,Tearsheet,Notifications): resolves CSP violations #6340

Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8670f1c
feat: adds codecov
AlexanderMelox Oct 16, 2024
e5b4ad5
Merge branch 'main' into 6108--codecov-tooling
AlexanderMelox Oct 16, 2024
68d3a6e
fix: adds codecov token
AlexanderMelox Oct 16, 2024
a0adc76
feat: adds codecov badge to README.mc
AlexanderMelox Oct 17, 2024
9dc5534
Merge branch 'main' into 6108--codecov-tooling
AlexanderMelox Oct 17, 2024
2f5f9c3
fix: removes community package
AlexanderMelox Oct 17, 2024
ec3de4c
Merge branch 'main' into 6108--codecov-tooling
AlexanderMelox Oct 17, 2024
0beb5ab
Merge branch 'main' into 6108--codecov-tooling
AlexanderMelox Oct 17, 2024
174e5bb
chore: adds violated components to forbid config
AlexanderMelox Oct 17, 2024
15ae1c2
feat(notifications): fixes csp violations
AlexanderMelox Oct 22, 2024
1b342a7
feat(tearsheet): fixes csp violations
AlexanderMelox Oct 22, 2024
bb1d3a6
feat: draft 1 adding isomorphic styles hook
AlexanderMelox Oct 24, 2024
9b5d06a
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Oct 31, 2024
2bf6969
chore: reverts to prev changes
AlexanderMelox Oct 31, 2024
8e9ad89
fix: package.json error
AlexanderMelox Oct 31, 2024
e6faf48
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Nov 1, 2024
0ddb611
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Nov 4, 2024
07c6fd7
fix: linting issues
AlexanderMelox Nov 6, 2024
e9fb52c
refactor(pageheader): tests
AlexanderMelox Nov 6, 2024
411acb2
feat(ts): adds props namespace
AlexanderMelox Nov 6, 2024
6cdc0be
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Nov 6, 2024
57ba415
feat: adds types to module declaration
AlexanderMelox Nov 6, 2024
4c5a05f
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
elycheea Nov 11, 2024
89183a7
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
elycheea Nov 12, 2024
6c4e0c9
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Jan 7, 2025
445ac60
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Jan 8, 2025
391cb5c
fix: module declarations
AlexanderMelox Jan 9, 2025
73e9c9f
fix: module declarations
AlexanderMelox Jan 9, 2025
2645335
fix: type declarations
AlexanderMelox Jan 9, 2025
1e80799
fix: type declarations
AlexanderMelox Jan 9, 2025
b5efb0e
fix: type declarations
AlexanderMelox Jan 9, 2025
c3499b5
fix: type declarations
AlexanderMelox Jan 9, 2025
3ecfff8
fix: type declarations
AlexanderMelox Jan 9, 2025
1d3abff
fix: type declarations
AlexanderMelox Jan 10, 2025
44976b1
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Jan 10, 2025
de8e0bf
fix: type declarations
AlexanderMelox Jan 10, 2025
d814951
fix(pageheader): styles that broke
AlexanderMelox Jan 10, 2025
51facfd
fix: changed icon import
AlexanderMelox Jan 10, 2025
8d92cef
fix: type declarations
AlexanderMelox Jan 10, 2025
f0f60d6
fix(notifications-panel): animation
AlexanderMelox Jan 13, 2025
81f06fb
chore: removes console.log
AlexanderMelox Jan 13, 2025
d408b0b
Merge branch 'main' into 6190--csp-spreadsheet-tearsheet-notification…
AlexanderMelox Jan 13, 2025
894d755
fix: removes comment
AlexanderMelox Jan 13, 2025
7337458
fix(tearsheet): styles
AlexanderMelox Jan 13, 2025
ab8da41
chore: remove console.log
AlexanderMelox Jan 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import { TextAreaProps, TextInputProps } from '@carbon/react';
import { CarbonIconType } from '@carbon/react/icons';
import { CarbonIconType } from '@carbon/icons-react';
matthewgallo marked this conversation as resolved.
Show resolved Hide resolved
import { NumberInputProps } from '@carbon/react/lib/components/NumberInput/NumberInput';
import {
Dispatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,16 +789,16 @@ export const DataSpreadsheetBody = forwardRef(
[
prepareRow,
renderRowHeader,
renderRowHeaderDirection,
rows,
hasCustomRowHeader,
activeCellCoordinates?.row,
selectionAreas,
handleRowHeaderClickEvent,
handleBodyCellClickEvent,
handleBodyCellHoverEvent,
defaultColumn,
columns,
defaultColumn,
renderRowHeaderDirection,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
import { pkg } from '../../settings';
import { prepareProps } from '../../global/js/utils/props-helper';
import { timeAgo } from './utils';
import { useClickOutside, usePreviousValue } from '../../global/js/hooks';
import {
useClickOutside,
useIsomorphicEffect,
usePreviousValue,
} from '../../global/js/hooks';
import usePrefersReducedMotion from '../../global/js/hooks/usePrefersReducedMotion';
import wrapFocus from '../../global/js/utils/wrapFocus';

Expand Down Expand Up @@ -646,6 +650,19 @@
},
]);

useIsomorphicEffect(() => {
// setTimeout ensures that this gets run
const timeout = setTimeout(() => {
if (notificationPanelRef.current && !reducedMotion) {
console.log({ open, notificationPanelRef });
AlexanderMelox marked this conversation as resolved.
Show resolved Hide resolved
notificationPanelRef.current.style.animation = open
? 'fade-in 250ms'
: 'fade-out forwards 250ms';

Check warning on line 660 in packages/ibm-products/src/components/NotificationsPanel/NotificationsPanel.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/NotificationsPanel/NotificationsPanel.tsx#L657-L660

Added lines #L657 - L660 were not covered by tests
}
}, 0);
return () => clearTimeout(timeout);
}, [open, reducedMotion]);

return shouldRender ? (
<>
<button
Expand All @@ -668,11 +685,6 @@
}
id={blockClass}
className={cx(blockClass, className, `${blockClass}__container`)}
style={{
animation: !reducedMotion
? `${open ? 'fade-in 250ms' : 'fade-out forwards 250ms'}`
: undefined,
}}
onAnimationEnd={onAnimationEnd}
ref={
(ref as MutableRefObject<HTMLDivElement | null>) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint react/forbid-component-props: 0 */

/**
* Copyright IBM Corp. 2020, 2023
*
Expand Down Expand Up @@ -337,10 +339,11 @@ describe('PageHeader', () => {
).toHaveLength(1);

// When withoutBackground is false this should result in the value 1 for opacity
const regStyle = new RegExp(
`--${prefix}--page-header--background-opacity: 1`
);
expect(header.getAttribute('style')).toMatch(regStyle);
const backgroundOpacity = window
.getComputedStyle(header)
.getPropertyValue(`--${prefix}--page-header--background-opacity`);

expect(backgroundOpacity).toBe('1');
});

const dataTestId = 'data-testid';
Expand Down Expand Up @@ -711,10 +714,10 @@ describe('PageHeader', () => {
const header = screen.getByTestId(dataTestId);

// When withoutBackground is true this should result in the value 0 for opacity
const regStyle = new RegExp(
`--${prefix}--page-header--background-opacity: 0`
);
expect(header.getAttribute('style')).toMatch(regStyle);
const backgroundOpacity = window
.getComputedStyle(header)
.getPropertyValue(`--${prefix}--page-header--background-opacity`);
expect(backgroundOpacity).toBe('0');
});

it('Works, for now, with deprecated props', async () =>
Expand All @@ -731,10 +734,10 @@ describe('PageHeader', () => {
const header = screen.getByTestId(dataTestId);

// When hasBackgroundAlways is false this should result in the value 0 for opacity
const regStyle = new RegExp(
`--${prefix}--page-header--background-opacity: 0`
);
expect(header.getAttribute('style')).toMatch(regStyle);
const backgroundOpacity = window
.getComputedStyle(header)
.getPropertyValue(`--${prefix}--page-header--background-opacity`);
expect(backgroundOpacity).toBe('0');
}));

it('PageHeader grid settings narrow and fullWidth', async () => {
Expand Down
27 changes: 23 additions & 4 deletions packages/ibm-products/src/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
deprecateProp,
prepareProps,
} from '../../global/js/utils/props-helper';
import { useNearestScroll, useWindowResize } from '../../global/js/hooks';
import {
useIsomorphicEffect,
useNearestScroll,
useWindowResize,
} from '../../global/js/hooks';

import { ActionBar } from '../ActionBar/';
import { BreadcrumbWithOverflow } from '../BreadcrumbWithOverflow';
Expand Down Expand Up @@ -421,6 +425,10 @@
navigationRowHeight?: number;
}

interface HTMLElementStyled extends HTMLElement {
style: CSSStyleDeclaration;
}

export let PageHeader = React.forwardRef(
(
{
Expand Down Expand Up @@ -476,8 +484,9 @@
});

// refs
const localHeaderRef = useRef(null);
const headerRef = ref || localHeaderRef;
const localHeaderRef = useRef<HTMLDivElement | null>(null);
const headerRef = (ref ||
localHeaderRef) as MutableRefObject<HTMLElementStyled>;
const sizingContainerRef: MutableRefObject<HTMLDivElement | null> =
useRef(null);
const offsetTopMeasuringRef = useRef(null);
Expand Down Expand Up @@ -903,6 +912,17 @@

const displayedBreadcrumbs = getBreadcrumbs();

useIsomorphicEffect(() => {
Object.keys(pageHeaderStyles).forEach((key) => {
// check if style is a css var
if (key.startsWith('--')) {
headerRef.current.style.setProperty(key, pageHeaderStyles[key]);
} else {
headerRef.current.style[key] = pageHeaderStyles[key];

Check warning on line 921 in packages/ibm-products/src/components/PageHeader/PageHeader.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/PageHeader/PageHeader.tsx#L920-L921

Added lines #L920 - L921 were not covered by tests
}
});
}, [headerRef, pageHeaderStyles]);

const subtitleRef = useRef<HTMLSpanElement>(null);
const isOverflowing = checkHeightOverflow(subtitleRef.current);
const subtitleContent = (
Expand All @@ -928,7 +948,6 @@
[`${blockClass}--has-navigation-tags-only`]: !navigation && tags,
},
])}
style={pageHeaderStyles}
ref={headerRef}
{...getDevtoolsProps(componentName)}
>
Expand Down
40 changes: 26 additions & 14 deletions packages/ibm-products/src/components/Tearsheet/TearsheetShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import {
import { ActionSet } from '../ActionSet';
import { Wrap } from '../../global/js/utils/Wrap';
import { usePortalTarget } from '../../global/js/hooks/usePortalTarget';
import { useIsomorphicEffect, usePreviousValue } from '../../global/js/hooks';
import { claimFocus, useFocus } from '../../global/js/hooks/useFocus';
import { usePreviousValue } from '../../global/js/hooks';
import { TearsheetAction } from './Tearsheet';

// The block part of our conventional BEM class names (bc__E--M).
Expand Down Expand Up @@ -384,6 +384,31 @@ export const TearsheetShell = React.forwardRef(
};
}, [open, size]);

const areAllSameSizeVariant = () => new Set(stack.sizes).size === 1;

useIsomorphicEffect(() => {
const setScaleValues = () => {
if (!areAllSameSizeVariant()) {
return {
[`--${bc}--stacking-scale-factor-single`]: 1,
[`--${bc}--stacking-scale-factor-double`]: 1,
};
}
return {
[`--${bc}--stacking-scale-factor-single`]: (width - 32) / width,
[`--${bc}--stacking-scale-factor-double`]: (width - 64) / width,
};
};
if (modalRef.current) {
modalRef.current.setAttribute(
'styles',
Object.entries(setScaleValues())
.map(([key, value]) => `${key}: ${value};`)
.join(' ') // converts the array of css properties and values to a string separated by semicolons
);
}
}, [modalRef, width]);

if (position <= depth) {
// Include a modal header if and only if one or more of these is given.
// We can't use a Wrap for the ModalHeader because ComposedModal requires
Expand All @@ -401,18 +426,6 @@ export const TearsheetShell = React.forwardRef(

const areAllSameSizeVariant = () => new Set(stack.sizes).size === 1;

const setScaleValues = () => {
if (!areAllSameSizeVariant()) {
return {
[`--${bc}--stacking-scale-factor-single`]: 1,
[`--${bc}--stacking-scale-factor-double`]: 1,
};
}
return {
[`--${bc}--stacking-scale-factor-single`]: (width - 32) / width,
[`--${bc}--stacking-scale-factor-double`]: (width - 64) / width,
};
};
return renderPortalUse(
<FeatureFlags enableExperimentalFocusWrapWithoutSentinels>
<ComposedModal
Expand All @@ -435,7 +448,6 @@ export const TearsheetShell = React.forwardRef(
[`${bc}--has-close`]: effectiveHasCloseIcon,
})}
decorator={decorator || deprecated_slug}
style={setScaleValues()}
containerClassName={cx(`${bc}__container`, {
[`${bc}__container--lower`]: verticalPosition === 'lower',
[`${bc}__container--mixed-size-stacking`]:
Expand Down
1 change: 0 additions & 1 deletion packages/ibm-products/src/custom-typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ declare module '@carbon/react' {
usePrefix,
} from '@carbon/react';
}

declare module '@carbon/colors';
declare module '@carbon/motion';
declare module '@carbon/feature-flags';
Loading