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

chore(cards): rename aiLabel to decorator #6509

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 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
30 changes: 23 additions & 7 deletions packages/ibm-products-styles/src/components/Card/_card.scss
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.
//

// NOTE: Please do not remove the duplicate `slug` and `ai-label` classes. We need both until slug is fully deprecated
// NOTE: Please do not remove the duplicate `slug` and `decorator` classes. We need both until slug is fully deprecated

// Standard imports.
@use '@carbon/styles/scss/theme' as *;
Expand Down Expand Up @@ -150,19 +150,31 @@ $block-class: #{c4p-settings.$pkg-prefix}--card;
right: $spacing-05;
}

.#{$block-class}__header__inner-wrapper--decorator {
position: absolute;
top: $spacing-05;
right: $spacing-05;

.#{c4p-settings.$carbon-prefix}--slug {
sangeethababu9223 marked this conversation as resolved.
Show resolved Hide resolved
position: relative;
top: unset;
right: unset;
}
}

.#{$block-class}__header-container--has-slug,
.#{$block-class}__header-container--has-ai-label {
.#{$block-class}__header-container--has-decorator {
width: 100%;
padding-right: $spacing-07;
}

.#{$block-class}__header-container--has-slug.#{$block-class}__header-container--has-actions,
.#{$block-class}__header-container--has-ai-label.#{$block-class}__header-container--has-actions {
.#{$block-class}__header-container--has-decorator.#{$block-class}__header-container--has-actions {
padding-right: $spacing-08;
}

.#{$block-class}__header-container--has-slug.#{$block-class}__header-container--large-tile-or-label,
.#{$block-class}__header-container--has-ai-label.#{$block-class}__header-container--large-tile-or-label {
.#{$block-class}__header-container--has-decorator.#{$block-class}__header-container--large-tile-or-label {
padding-right: $spacing-09;
}

Expand All @@ -176,16 +188,20 @@ $block-class: #{c4p-settings.$pkg-prefix}--card;
}

.#{$block-class}--has-slug,
.#{$block-class}--has-ai-label {
.#{$block-class}--has-decorator {
sangeethababu9223 marked this conversation as resolved.
Show resolved Hide resolved
@include utilities.ai-popover-gradient('default', 0, 'layer');

border: 1px solid transparent;
box-shadow: inset 0 -80px 70px -65px $ai-inner-shadow,
0 4px 10px 2px $ai-drop-shadow;
}

.#{$block-class}--has-decorator-non-ai-label {
background-color: $layer-01;
}

.#{$block-class}__clickable.#{$block-class}--has-slug::before,
.#{$block-class}__clickable.#{$block-class}--has-ai-label::before {
.#{$block-class}__clickable.#{$block-class}--has-decorator::before {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.#{$block-class}__clickable.#{$block-class}--has-decorator::before {
.#{$block-class}__clickable.#{$block-class}--has-decorator::before {

I think for has--decorator, we don’t want to tie this to the popover styles since this could be separate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @elycheea,
This is updated.

@include utilities.ai-popover-gradient('hover', 0, 'layer');

position: absolute;
Expand All @@ -201,7 +217,7 @@ $block-class: #{c4p-settings.$pkg-prefix}--card;
}

.#{$block-class}__clickable.#{$block-class}--has-slug:hover::before,
.#{$block-class}__clickable.#{$block-class}--has-ai-label:hover::before {
.#{$block-class}__clickable.#{$block-class}--has-decorator:hover::before {
opacity: 1;
}

Expand Down
25 changes: 14 additions & 11 deletions packages/ibm-products/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ interface CardProp extends PropsWithChildren {

/**
* Clickable tiles only accept a boolean value of true and display a hollow slug.
* @deprecated please use the `aiLabel` prop
* @deprecated please use the `decorator` prop
*/
slug?: ReactNode | boolean;

/**
* Optional prop that is intended for any scenario where something is being generated by AI to reinforce AI transparency, accountability, and explainability at the UI level.
* Optional prop that allows you to pass any component.
*/
aiLabel?: ReactNode | boolean;
decorator?: ReactNode | boolean;

status?: 'complete' | 'incomplete';
title?: ReactNode;
Expand All @@ -103,7 +103,7 @@ export const Card = forwardRef(
// The component props, in alphabetical order (for consistency).
actionIcons = Object.freeze([]),
actionsPlacement = 'bottom',
aiLabel,
decorator,
metadata = Object.freeze([]),
children,
className,
Expand Down Expand Up @@ -262,7 +262,10 @@ export const Card = forwardRef(
[`${blockClass}__clickable`]: clickable,
[`${blockClass}__media-left`]: mediaPosition === 'left',
[`${blockClass}--has-slug`]: !!slug,
[`${blockClass}--has-ai-label`]: !!aiLabel,
[`${blockClass}--has-decorator-non-ai-label`]:
!!decorator && decorator['type']?.displayName !== 'AILabel',
[`${blockClass}--has-decorator`]:
!!decorator && decorator['type']?.displayName === 'AILabel',
sangeethababu9223 marked this conversation as resolved.
Show resolved Hide resolved
},
className
),
Expand All @@ -287,7 +290,7 @@ export const Card = forwardRef(

const getHeaderProps = () => ({
actions: actionsPlacement === 'top' ? getActions() : '',
aiLabel,
decorator,
noActionIcons:
getIcons().length > 0 && actionsPlacement === 'top' ? false : true,
actionsPlacement,
Expand Down Expand Up @@ -395,13 +398,13 @@ Card.propTypes = {
})
),
actionsPlacement: PropTypes.oneOf(['top', 'bottom']),
/**
* Optional prop that is intended for any scenario where something is being generated by AI to reinforce AI transparency, accountability, and explainability at the UI level.
*/
aiLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),
children: PropTypes.node,
className: PropTypes.string,
clickZone: PropTypes.oneOf(['one', 'two', 'three']),
/**
* Optional prop that allows you to pass any component.
*/
decorator: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),
/**@ts-ignore */
description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
disabled: PropTypes.bool,
Expand Down Expand Up @@ -455,7 +458,7 @@ Card.propTypes = {
/**
* **Experimental:** For all cases a `Slug` component can be provided.
* Clickable tiles only accept a boolean value of true and display a hollow slug.
* @deprecated please use the `aiLabel` prop
* @deprecated please use the `decorator` prop
*/
slug: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),

Expand Down
38 changes: 23 additions & 15 deletions packages/ibm-products/src/components/Card/CardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
interface CardHeaderProps {
actions?: ReactNode;
/**
* Optional prop that is intended for any scenario where something is being generated by AI to reinforce AI transparency, accountability, and explainability at the UI level.
* Optional prop that allows you to pass any component.
*/
aiLabel?: ReactNode | boolean;
decorator?: ReactNode | boolean;
description?: ReactNode;
hasActions?: boolean;
/**
Expand All @@ -46,7 +46,7 @@
/**
* **Experimental:** For all cases a `Slug` component can be provided.
* Clickable tiles only accept a boolean value of true and display a hollow slug.
* @deprecated please use the `aiLabel` prop
* @deprecated please use the `decorator` prop
*/
slug?: ReactNode;

Expand All @@ -56,7 +56,7 @@

export const CardHeader = ({
actions,
aiLabel,
decorator,
noActionIcons,
onPrimaryButtonClick,
onSecondaryButtonClick,
Expand Down Expand Up @@ -107,17 +107,17 @@
</svg>
);

let normalizedAiLabel: React.ReactElement<any> | null = null;
if (aiLabel || slug) {
let normalizedDecorator: React.ReactElement<any> | null = null;
if (decorator || slug) {
if (
inClickableCard ||
typeof aiLabel === 'boolean' ||
typeof decorator === 'boolean' ||

Check warning on line 114 in packages/ibm-products/src/components/Card/CardHeader.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Card/CardHeader.tsx#L114

Added line #L114 was not covered by tests
typeof slug === 'boolean'
) {
normalizedAiLabel = hollowAiIcon;
normalizedDecorator = hollowAiIcon;

Check warning on line 117 in packages/ibm-products/src/components/Card/CardHeader.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Card/CardHeader.tsx#L117

Added line #L117 was not covered by tests
} else {
const element = aiLabel || slug;
normalizedAiLabel = React.cloneElement(
const element = decorator || slug;
normalizedDecorator = React.cloneElement(

Check warning on line 120 in packages/ibm-products/src/components/Card/CardHeader.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Card/CardHeader.tsx#L119-L120

Added lines #L119 - L120 were not covered by tests
element as React.ReactElement<any>,
{
size:
Expand All @@ -133,7 +133,7 @@
className={cx([
`${headerClass}-container`,
{ [`${headerClass}-container--has-slug`]: !!slug },
{ [`${headerClass}-container--has-ai-label`]: !!aiLabel },
{ [`${headerClass}-container--has-decorator`]: !!decorator },
{ [`${headerClass}-container--has-actions`]: !!hasActions },
{
[`${headerClass}-container--large-tile-or-label`]:
Expand Down Expand Up @@ -180,7 +180,15 @@
)}
</div>
)}
{normalizedAiLabel}
{slug ? (
normalizedDecorator

Check warning on line 184 in packages/ibm-products/src/components/Card/CardHeader.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Card/CardHeader.tsx#L184

Added line #L184 was not covered by tests
) : decorator ? (
<div className={`${blockClass}__header__inner-wrapper--decorator`}>

Check warning on line 186 in packages/ibm-products/src/components/Card/CardHeader.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Card/CardHeader.tsx#L186

Added line #L186 was not covered by tests
{normalizedDecorator}
</div>
) : (
''
)}
</div>
</div>
);
Expand All @@ -189,9 +197,9 @@
CardHeader.propTypes = {
actions: PropTypes.oneOfType([PropTypes.array, PropTypes.node]),
/**
* Optional prop that is intended for any scenario where something is being generated by AI to reinforce AI transparency, accountability, and explainability at the UI level.
* Optional prop that allows you to pass any component.
*/
aiLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),
decorator: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),
description: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
Expand Down Expand Up @@ -219,7 +227,7 @@
/**
* **Experimental:** For all cases a `Slug` component can be provided.
* Clickable tiles only accept a boolean value of true and display a hollow slug.
* @deprecated please use the `aiLabel` prop
* @deprecated please use the `decorator` prop
*/
slug: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const DocsPage = () => (
<ExpressiveCard
label="Label"
primaryButtonText="Primary"
aiLabel={<AILabel><AILabelContent>{renderedContent}</AILabelContent></AILabel>}
decorator={<AILabel><AILabelContent>{renderedContent}</AILabelContent></AILabel>}
title="Title">
<p>
expressive card body content block. description inviting the user to take action on the card.
Expand All @@ -64,7 +64,7 @@ const DocsPage = () => (
},
{
description:
'Clickable tiles only accept a boolean value of true for the aiLabel property.',
'Clickable tiles only accept a boolean value of true for the decorator property.',
source: {
language: 'html',
code: `
Expand All @@ -73,7 +73,7 @@ const DocsPage = () => (
primaryButtonText="Primary"
onClick={() => {}}
onKeyDown={() => {}}
aiLabel={true}
decorator={true}
title="Title">
<p>
expressive card body content block. description inviting the user to take action on the card.
Expand Down
Loading
Loading