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(createtearsheet): rename slug to decorator #6602

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -149,13 +149,13 @@ sections, you can utilize the below included class names.
{
title: 'With AI Label',
description:
'An AI Label is intended for any scenario where something is being generated by AI to reinforce AI transparency, accountability, and explainability at the UI level. A Carbon AI Label can be provided to the CreateTearsheet component by including an `slug` property on it and providing the carbon AILabel component as its own custom component. Please note that the `slug` and `aiLabel` attributes are being deprecated and will soon be replaced by `decorator` to align with the Carbon.',
'An AI Label is intended for any scenario where something is being generated by AI to reinforce AI transparency, accountability, and explainability at the UI level. A Carbon AI Label can be provided to the CreateTearsheet component by including a `decorator` or `slug` property on it and providing the carbon AILabel component as its own custom component. Please note that the `slug` attribute is being deprecated and will soon be replaced by `decorator` to align with the Carbon.<br/> The `decorator` is versatile and can also be used to render other components.',
source: {
language: 'html',
code: `
<CreateTearsheet
{...args}
slug={
decorator={
<AILabel
className="ai-label-container"
autoAlign={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

import { slugArgTypes } from '../../global/js/story-parts/slug';
import {
decoratorArgTypes,
slugArgTypes,
} from '../../global/js/story-parts/decorator';
import styles from './_storybook-styles.scss?inline';
import { CreateTearsheet } from './CreateTearsheet';
import DocsPage from './CreateTearsheet.docs-page';
Expand All @@ -26,6 +29,7 @@ export default {
open: { control: { disable: true } },
children: { control: { disable: true } },
...slugArgTypes(),
...decoratorArgTypes(),
},
parameters: {
styles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
useResetCreateComponent,
useValidCreateStepCount,
} from '../../global/js/hooks';
import { deprecateProp } from '../../global/js/utils/props-helper';

import { CreateInfluencer } from '../CreateInfluencer';
import { Form } from '@carbon/react';
Expand Down Expand Up @@ -87,6 +88,11 @@ export interface CreateTearsheetProps extends PropsWithChildren {
*/
experimentalSecondarySubmitText?: string;

/**
* Optional prop that allows you to pass any component.
*/
decorator?: ReactNode;

/**
* A description of the flow, displayed in the header area of the tearsheet.
*/
Expand Down Expand Up @@ -139,11 +145,6 @@ export interface CreateTearsheetProps extends PropsWithChildren {
*/
open?: boolean;

/**
* **Experimental:** Provide a `Slug` component to be rendered inside the `Tearsheet` component
*/
slug?: ReactNode;

/**
* The submit button text
*/
Expand All @@ -162,6 +163,12 @@ export interface CreateTearsheetProps extends PropsWithChildren {
* to allow an action bar navigation or breadcrumbs to also show through.
*/
verticalPosition?: 'normal' | 'lower';

// Deprecated props
/**
* @deprecated Property replaced by `decorator`
*/
slug?: ReactNode;
}

interface Step {
Expand Down Expand Up @@ -190,7 +197,8 @@ export let CreateTearsheet = forwardRef(
onRequestSubmit,
open,
firstFocusElement,
slug,
slug: deprecated_slug,
decorator,
submitButtonText,
title,
verticalPosition = 'normal',
Expand Down Expand Up @@ -305,7 +313,7 @@ export let CreateTearsheet = forwardRef(
onClose,
open,
size: 'wide',
slug,
decorator: decorator || deprecated_slug,
title,
verticalPosition,
closeIconDescription: '',
Expand Down Expand Up @@ -346,6 +354,12 @@ CreateTearsheet = pkg.checkComponentEnabled(CreateTearsheet, componentName);
// is used in preference to relying on function.name.
CreateTearsheet.displayName = componentName;

const deprecatedProps = {
/**
* @deprecated Property replaced by `decorator`
*/
slug: deprecateProp(PropTypes.node, 'Property replaced by `decorator`'),
};
// Note that the descriptions here should be kept in sync with those for the
// corresponding props for TearsheetNarrow and TearsheetShell components.
CreateTearsheet.propTypes = {
Expand All @@ -369,6 +383,11 @@ CreateTearsheet.propTypes = {
*/
className: PropTypes.string,

/**
* Optional prop that allows you to pass any component.
*/
decorator: PropTypes.node,

/**
* A description of the flow, displayed in the header area of the tearsheet.
*/
Expand Down Expand Up @@ -426,11 +445,6 @@ CreateTearsheet.propTypes = {
*/
open: PropTypes.bool,

/**
* **Experimental:** Provide a `Slug` component to be rendered inside the `Tearsheet` component
*/
slug: PropTypes.node,

/**
* The submit button text
*/
Expand All @@ -449,4 +463,5 @@ CreateTearsheet.propTypes = {
* to allow an action bar navigation or breadcrumbs to also show through.
*/
verticalPosition: PropTypes.oneOf(['normal', 'lower']),
...deprecatedProps,
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import cx from 'classnames';
import { pkg } from '../../../settings';
import { CreateTearsheet } from '../CreateTearsheet';
import { CreateTearsheetStep } from '../CreateTearsheetStep';
import { SlugSample } from '../../../global/js/story-parts/slug';
import { sampleDecorator } from '../../../global/js/story-parts/decorator';

const blockClass = `${pkg.prefix}--tearsheet-create-multi-step`;

Expand Down Expand Up @@ -56,6 +56,7 @@ export const MultiStepTearsheet = ({
label,
nextButtonText,
slug,
decorator,
submitButtonText,
title,
...rest
Expand Down Expand Up @@ -115,7 +116,8 @@ export const MultiStepTearsheet = ({
})
}
firstFocusElement={firstFocusElement}
slug={slug && SlugSample()}
slug={slug && sampleDecorator(slug)}
decorator={decorator && sampleDecorator(decorator)}
{...rest}
>
<CreateTearsheetStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { pkg } from '../../../settings';
import { CreateTearsheet } from '../CreateTearsheet';
import { CreateTearsheetStep } from '../CreateTearsheetStep';
import { NoDataIllustration } from '../../EmptyStates/assets/NoDataIllustration';
import { SlugSample } from '../../../global/js/story-parts/slug';
import { sampleDecorator } from '../../../global/js/story-parts/decorator';

const blockClass = `${pkg.prefix}--tearsheet-create-multi-step`;

Expand All @@ -38,6 +38,7 @@ export const MultiStepWithIntro = ({
label,
nextButtonText,
slug,
decorator,
submitButtonText,
title,
}) => {
Expand Down Expand Up @@ -92,7 +93,8 @@ export const MultiStepWithIntro = ({
}, simulatedDelay);
})
}
slug={slug && SlugSample()}
slug={slug && sampleDecorator(slug)}
decorator={decorator && sampleDecorator(decorator)}
>
<CreateTearsheetStep
title="Select a category"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import cx from 'classnames';
import { pkg } from '../../../settings';
import { CreateTearsheet } from '../CreateTearsheet';
import { CreateTearsheetStep } from '../CreateTearsheetStep';
import { SlugSample } from '../../../global/js/story-parts/slug';
import { sampleDecorator } from '../../../global/js/story-parts/decorator';

const blockClass = `${pkg.prefix}--tearsheet-create-multi-step`;

Expand All @@ -25,6 +25,7 @@ export const MultiStepWithStepInErrorState = ({
label,
nextButtonText,
slug,
decorator,
submitButtonText,
title,
}) => {
Expand Down Expand Up @@ -72,7 +73,8 @@ export const MultiStepWithStepInErrorState = ({
}, simulatedDelay);
})
}
slug={slug && SlugSample()}
slug={slug && sampleDecorator(slug)}
decorator={decorator && sampleDecorator(decorator)}
>
<CreateTearsheetStep
title="Topic name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { pkg } from '../../settings';
import { CreateTearsheetNarrow } from '.';
import styles from './_storybook-styles.scss?inline';
import { StoryDocsPage } from '../../global/js/utils/StoryDocsPage';
import { SlugSample, slugArgTypes } from '../../global/js/story-parts/slug';
import {
sampleDecorator,
slugArgTypes,
decoratorArgTypes,
} from '../../global/js/story-parts/decorator';

export default {
title: 'IBM Products/Patterns/Create flows/CreateTearsheetNarrow',
Expand All @@ -28,6 +32,7 @@ export default {
argTypes: {
children: { control: { disable: true } },
...slugArgTypes(),
...decoratorArgTypes(),
},
parameters: {
styles,
Expand All @@ -54,7 +59,7 @@ const defaultStoryProps = {
selectorPrimaryFocus: '#tearsheet-narrow-story-text-input--1',
};

const Template = ({ slug, ...args }) => {
const Template = ({ slug, decorator, ...args }) => {
const [open, setOpen] = useState(false);
const [topicName, setTopicName] = useState('');
const [partitionCount, setPartitionCount] = useState(1);
Expand All @@ -80,7 +85,8 @@ const Template = ({ slug, ...args }) => {
onRequestClose={() => setOpen(false)}
onRequestSubmit={action('onRequestSubmit action called')}
disableSubmit={!topicName || numberInputsInvalid}
slug={slug && SlugSample()}
slug={slug && sampleDecorator(slug)}
decorator={decorator && sampleDecorator(decorator)}
{...args}
>
<TextInput
Expand Down Expand Up @@ -156,7 +162,7 @@ const Template = ({ slug, ...args }) => {
);
};

const WithValidationTemplate = ({ slug, ...args }) => {
const WithValidationTemplate = ({ slug, decorator, ...args }) => {
const [open, setOpen] = useState(false);
const [topicName, setTopicName] = useState('');
const [partitionCount, setPartitionCount] = useState(1);
Expand Down Expand Up @@ -187,7 +193,8 @@ const WithValidationTemplate = ({ slug, ...args }) => {
}}
onRequestSubmit={action('onRequestSubmit action called')}
disableSubmit={!topicName || numberInputsInvalid}
slug={slug && SlugSample()}
slug={slug && sampleDecorator(slug)}
decorator={decorator && sampleDecorator(decorator)}
{...args}
>
<FormGroup
Expand Down
98 changes: 98 additions & 0 deletions packages/ibm-products/src/global/js/story-parts/decorator.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright IBM Corp. 2024, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {
AILabel,
AILabelContent,
Toggletip,
ToggletipButton,
ToggletipContent,
} from '@carbon/react';
import { Information } from '@carbon/react/icons';

export const sampleDecorator = (decorator) => {
switch (decorator) {
case 1:
return (

Check warning on line 21 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L18-L21

Added lines #L18 - L21 were not covered by tests
<AILabel className="decorator-container" size="xs">
<AILabelContent>
<div>
<p className="secondary">AI Explained</p>
<h1>84%</h1>
<p className="secondary bold">Confidence score</p>
<p className="secondary">
This is not really Lorem Ipsum but the spell checker did not
like the previous text with it&apos;s non-words which is why
this unwieldy sentence, should one choose to call it that, here.
</p>
<hr />
<p className="secondary">Model type</p>
<p className="bold">Foundation model</p>
</div>
</AILabelContent>
</AILabel>
);
case 2:
return (

Check warning on line 41 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L40-L41

Added lines #L40 - L41 were not covered by tests
<Toggletip>
<ToggletipButton label="Additional information">
<Information />
</ToggletipButton>
<ToggletipContent>
<p>Custom content here</p>
</ToggletipContent>
</Toggletip>
);
default:
return;

Check warning on line 52 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L51-L52

Added lines #L51 - L52 were not covered by tests
}
};

export const decoratorArgTypes = ({
_default = 0,
withHollow = false,
} = {}) => {
const decorator = {

Check warning on line 60 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L56-L60

Added lines #L56 - L60 were not covered by tests
control: {
type: 'select',
labels: {
0: 'No AI Label',
1: 'with AI Label',
2: 'With non AI Label component',
},
default: _default,
},
options: [0, 1, 2],
};

if (withHollow) {
decorator.control.labels[3] = 'with hollow AI Label (boolean)';
decorator.options.push(3);

Check warning on line 75 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L73-L75

Added lines #L73 - L75 were not covered by tests
}
return { decorator };

Check warning on line 77 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L77

Added line #L77 was not covered by tests
};

export const slugArgTypes = ({ _default = 0, withHollow = false } = {}) => {
const slug = {

Check warning on line 81 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L80-L81

Added lines #L80 - L81 were not covered by tests
control: {
type: 'select',
labels: {
0: 'No AI slug',
1: 'with AI Slug',
},
default: _default,
},
options: [0, 1],
};

if (withHollow) {
slug.control.labels[2] = 'with hollow AI Slug (boolean)';
slug.options.push(2);

Check warning on line 95 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L93-L95

Added lines #L93 - L95 were not covered by tests
}
return { slug };

Check warning on line 97 in packages/ibm-products/src/global/js/story-parts/decorator.jsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/global/js/story-parts/decorator.jsx#L97

Added line #L97 was not covered by tests
};
Loading