diff --git a/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap index 4fc8fdf09a26..81a38fcd9baf 100644 --- a/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -277,9 +277,19 @@ Array [ "slugBackground", "slugBackgroundHover", "slugCalloutAuraEnd", + "slugCalloutAuraEndHover01", + "slugCalloutAuraEndHover02", + "slugCalloutAuraEndSelected", "slugCalloutAuraStart", + "slugCalloutAuraStartHover01", + "slugCalloutAuraStartHover02", + "slugCalloutAuraStartSelected", "slugCalloutGradientBottom", + "slugCalloutGradientBottomHover", + "slugCalloutGradientBottomSelected", "slugCalloutGradientTop", + "slugCalloutGradientTopHover", + "slugCalloutGradientTopSelected", "slugGradient", "slugGradientHover", "slugHollowHover", diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index df340fa99a63..43e93b4f6246 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -584,6 +584,9 @@ Map { "disabled": Object { "type": "bool", }, + "hasRoundedCorners": Object { + "type": "bool", + }, "href": Object { "type": "string", }, @@ -3081,6 +3084,9 @@ Map { "expanded": Object { "type": "bool", }, + "hasRoundedCorners": Object { + "type": "bool", + }, "id": Object { "type": "string", }, @@ -6646,6 +6652,9 @@ Map { "disabled": Object { "type": "bool", }, + "hasRoundedCorners": Object { + "type": "bool", + }, "id": Object { "type": "string", }, @@ -6665,6 +6674,9 @@ Map { "selected": Object { "type": "bool", }, + "slug": Object { + "type": "node", + }, "tabIndex": Object { "type": "number", }, @@ -8591,7 +8603,13 @@ Map { "className": Object { "type": "string", }, + "hasRoundedCorners": Object { + "type": "bool", + }, "light": [Function], + "slug": Object { + "type": "node", + }, }, "render": [Function], }, diff --git a/packages/react/src/components/Tile/Tile.stories.js b/packages/react/src/components/Tile/Tile.stories.js index dd7de3a3d573..f46063a6fcf7 100644 --- a/packages/react/src/components/Tile/Tile.stories.js +++ b/packages/react/src/components/Tile/Tile.stories.js @@ -23,7 +23,15 @@ import { TileBelowTheFoldContent, } from './'; import TileGroup from '../TileGroup/TileGroup'; -import { Download } from '@carbon/icons-react'; +import { IconButton } from '../IconButton'; +import { Slug, SlugContent, SlugActions } from '../Slug'; +import { + Download, + View, + FolderOpen, + Folders, + ArrowRight, +} from '@carbon/icons-react'; export default { title: 'Components/Tile', @@ -57,6 +65,159 @@ export const Default = () => { ); }; +export const SlugTest = (args) => { + const slug = ( + + +
+

AI Explained

+

84%

+

Confidence score

+

+ Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed + do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua. +

+
+

Model type

+

Foundation model

+
+ + + + + + + + + + + + +
+
+ ); + + return ( +
+ +

Title

+

+ Lorem ipsum dolor sit amet consectetur. Posuere duis fermentum sit at + consectetur turpis mauris gravida penatibus. +

+
+
+

Data Quality

+

85%

+
+
+

Label text

+

16%

+
+
+
+ +

Title

+

+ Lorem ipsum dolor sit amet consectetur. Posuere duis fermentum sit at + consectetur turpis mauris gravida penatibus. +

+
+
+

Data Quality

+

85%

+
+
+

Label text

+

16%

+
+
+
+ +

Title

+

+ Lorem ipsum dolor sit amet consectetur. Posuere duis fermentum sit at + consectetur turpis mauris gravida penatibus. +

+
+
+

Data Quality

+

85%

+
+
+

Label text

+

16%

+
+
+
+ + +

Title

+

+ Lorem ipsum dolor sit amet consectetur. Posuere duis fermentum sit + at consectetur turpis mauris gravida penatibus. +

+
+
+

Data Quality

+

85%

+
+
+

Label text

+

16%

+
+
+
+ +
Expanded Section
+

+ Lorem ipsum dolor sit amet consectetur. Posuere duis fermentum sit + at consectetur turpis mauris. +

+
+
+
+ ); +}; + +SlugTest.argTypes = { + hasRoundedCorners: { + control: { + type: 'boolean', + }, + }, + children: { + table: { + disable: true, + }, + }, + className: { + table: { + disable: true, + }, + }, + slug: { + table: { + disable: true, + }, + }, +}; + export const DefaultWithLayer = () => ( {(layer) => ( diff --git a/packages/react/src/components/Tile/Tile.tsx b/packages/react/src/components/Tile/Tile.tsx index 3f84d76105d4..2fb559804d78 100644 --- a/packages/react/src/components/Tile/Tile.tsx +++ b/packages/react/src/components/Tile/Tile.tsx @@ -9,7 +9,7 @@ import React, { type ChangeEvent, type ComponentType, } from 'react'; -import PropTypes from 'prop-types'; +import PropTypes, { ReactNodeLike } from 'prop-types'; import cx from 'classnames'; import { Checkbox, @@ -38,22 +38,45 @@ export interface TileProps extends HTMLAttributes { className?: string; /** @deprecated */ light?: boolean; + + /** + * Specify if the `Tile` component should be rendered with rounded corners. Only valid + * when `slug` prop is present + */ + hasRoundedCorners?: boolean; + + /** + * Provide a `Slug` component to be rendered inside the `SelectableTile` component + */ + slug?: ReactNodeLike; } export const Tile = React.forwardRef(function Tile( - { children, className, light = false, ...rest }, + { + children, + className, + light = false, + slug, + hasRoundedCorners = false, + ...rest + }, ref ) { const prefix = usePrefix(); const tileClasses = cx( `${prefix}--tile`, - light && `${prefix}--tile--light`, + { + [`${prefix}--tile--light`]: light, + [`${prefix}--tile--slug`]: slug, + [`${prefix}--tile--slug-rounded`]: slug && hasRoundedCorners, + }, className ); return (
{children} + {slug}
); }); @@ -70,6 +93,12 @@ Tile.propTypes = { */ className: PropTypes.string, + /** + * Specify if the `Tile` component should be rendered with rounded corners. Only valid + * when `slug` prop is present + */ + hasRoundedCorners: PropTypes.bool, + /** * `true` to use the light version. For use on $ui-01 backgrounds only. * Don't use this to make tile background color same as container background color. @@ -80,6 +109,11 @@ Tile.propTypes = { PropTypes.bool, 'The `light` prop for `Tile` is no longer needed and has been deprecated. It will be removed in the next major release. Use the Layer component instead.' ), + + /** + * Provide a `Slug` component to be rendered inside the `Tile` component + */ + slug: PropTypes.node, }; export interface ClickableTileProps extends HTMLAttributes { @@ -99,6 +133,12 @@ export interface ClickableTileProps extends HTMLAttributes { */ disabled?: boolean; + /** + * Specify if the `ClickableTile` component should be rendered with rounded corners. + * Only valid when `slug` prop is present + */ + hasRoundedCorners?: boolean; + /** * The href for the link. */ @@ -123,6 +163,11 @@ export interface ClickableTileProps extends HTMLAttributes { * The rel property for the link. */ rel?: string; + + /** + * Specify if a `Slug` icon should be rendered inside the `ClickableTile` + */ + slug?: boolean; } export const ClickableTile = React.forwardRef< @@ -139,6 +184,8 @@ export const ClickableTile = React.forwardRef< onClick = () => {}, onKeyDown = () => {}, renderIcon: Icon, + hasRoundedCorners, + slug, ...rest }, ref @@ -147,8 +194,12 @@ export const ClickableTile = React.forwardRef< const classes = cx( `${prefix}--tile`, `${prefix}--tile--clickable`, - clicked && `${prefix}--tile--is-clicked`, - light && `${prefix}--tile--light`, + { + [`${prefix}--tile--is-clicked`]: clicked, + [`${prefix}--tile--light`]: light, + [`${prefix}--tile--slug`]: slug, + [`${prefix}--tile--slug-rounded`]: slug && hasRoundedCorners, + }, className ); @@ -168,6 +219,24 @@ export const ClickableTile = React.forwardRef< onKeyDown(evt); } + // To Do: Replace with an an icon from `@carbon/react` + // since the hollow slug in `ClickableTile` is not interactive + const hollowSlugIcon = ( + + + + + ); + const v12DefaultIcons = useFeatureFlag('enable-v12-tile-default-icons'); if (v12DefaultIcons) { if (!Icon) { @@ -195,7 +264,12 @@ export const ClickableTile = React.forwardRef< ref={ref} disabled={disabled} {...rest}> - {children} + {slug ? ( +
{children}
+ ) : ( + children + )} + {slug && hollowSlugIcon} {Icon &&