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

feat(Slug): implement AI Slug #14998

Merged
merged 21 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Code generated by carbon-components-react. DO NOT EDIT.
//
// Copyright IBM Corp. 2018, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward '@carbon/styles/scss/components/slug';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Code generated by carbon-components-react. DO NOT EDIT.
//
// Copyright IBM Corp. 2018, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward '@carbon/styles/scss/components/slug/slug';
9 changes: 9 additions & 0 deletions packages/carbon-components/scss/components/slug/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Code generated by carbon-components. DO NOT EDIT.
//
// Copyright IBM Corp. 2018, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward '@carbon/styles/scss/components/slug';
9 changes: 9 additions & 0 deletions packages/carbon-components/scss/components/slug/_slug.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Code generated by carbon-components. DO NOT EDIT.
//
// Copyright IBM Corp. 2018, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward '@carbon/styles/scss/components/slug/slug';
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ Array [
"skeletonElement",
"slow01",
"slow02",
"slugBackground",
"slugBackgroundHover",
"slugGradient",
"slugGradientHover",
"slugHollowHover",
"spacing",
"spacing01",
"spacing02",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8780,6 +8780,9 @@ Map {
"as": Object {
"type": "elementType",
},
"autoAlign": Object {
"type": "bool",
},
"children": Object {
"type": "node",
},
Expand Down
9 changes: 9 additions & 0 deletions packages/react/scss/components/slug/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Code generated by @carbon/react. DO NOT EDIT.
//
// Copyright IBM Corp. 2018, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward '@carbon/styles/scss/components/slug';
9 changes: 9 additions & 0 deletions packages/react/scss/components/slug/_slug.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Code generated by @carbon/react. DO NOT EDIT.
//
// Copyright IBM Corp. 2018, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward '@carbon/styles/scss/components/slug/slug';
132 changes: 132 additions & 0 deletions packages/react/src/components/Slug/Slug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* 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 cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

import { usePrefix } from '../../internal/usePrefix';
import {
Toggletip,
ToggletipButton,
ToggletipContent,
ToggletipActions,
} from '../Toggletip';

const Slug = React.forwardRef(function Slug(
{
aiText = 'AI',
align,
autoAlign = false,
dotType,
kind,
size = 'xs',
slugContent,
},
ref
) {
const prefix = usePrefix();

const slugClasses = cx({
[`${prefix}--ai-slug`]: true,
tay1orjones marked this conversation as resolved.
Show resolved Hide resolved
[`${prefix}--ai-slug--inline-with-content`]:
kind === 'inline' && slugContent,
});

const slugButtonClasses = cx({
[`${prefix}--ai-slug__button`]: true,
[`${prefix}--ai-slug__button--${size}`]: size,
[`${prefix}--ai-slug__button--${kind}`]: kind,
});

const aiTextClasses = cx({
[`${prefix}--ai-slug__text`]: true,
[`${prefix}--ai-slug__text--dot-${dotType}`]: dotType,
});

const isInline = kind === 'inline';

return (
<div className={slugClasses} ref={ref}>
{isInline ? (
<div className={slugButtonClasses}>
<span className={aiTextClasses}>{aiText}</span>
{slugContent && (
<span className={`${prefix}--ai-slug__content`}>{slugContent}</span>
)}
</div>
) : (
<Toggletip align={align} autoAlign={autoAlign}>
<ToggletipButton
className={slugButtonClasses}
label="Show information">
<span className={`${prefix}--ai-slug__text`}>{aiText}</span>
</ToggletipButton>
<ToggletipContent>
{slugContent}
<ToggletipActions></ToggletipActions>
</ToggletipContent>
</Toggletip>
)}
</div>
);
});

Slug.propTypes = {
/**
* Specify the correct translation of the AI text
*/
aiText: PropTypes.string,

/**
* Specify how the popover should align with the button
*/
align: PropTypes.oneOf([
'top',
'top-left',
'top-right',

'bottom',
'bottom-left',
'bottom-right',

'left',
'left-bottom',
'left-top',

'right',
'right-bottom',
'right-top',
]),

/**
* Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
*/
autoAlign: PropTypes.bool,

/**
* Specify the type of dot that should be rendered in front of the inline variant
*/
dotType: PropTypes.oneOf(['default', 'hollow']),

/**
* Specify the type of Slug, from the following list of types:
*/
kind: PropTypes.oneOf(['default', 'hollow', 'inline']),

/**
* Specify the size of the button, from the following list of sizes:
*/
size: PropTypes.oneOf(['mini', '2xs', 'xs', 'sm', 'md', 'lg', 'xl']),

/**
* Specify the content you want rendered inside the slug ToggleTip
*/
slugContent: PropTypes.node,
};

export default Slug;
1 change: 1 addition & 0 deletions packages/react/src/components/Slug/Slug.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
143 changes: 143 additions & 0 deletions packages/react/src/components/Slug/Slug.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable no-console */

import React from 'react';

import Slug from '.';
import mdx from './Slug.mdx';
import './slug-story.scss';

export default {
title: 'Experimental/unstable__Slug',
component: Slug,
parameters: {
docs: {
page: mdx,
},
},
};

export const Default = () => (
<>
<div className="slug-container">
<Slug
autoAlign
size="mini"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua. Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
autoAlign
size="2xs"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
autoAlign
size="xs"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
autoAlign
size="sm"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
autoAlign
size="md"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
autoAlign
size="lg"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
autoAlign
size="xl"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
</div>
<div className="slug-container">
<Slug
kind="hollow"
autoAlign
size="mini"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua. Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
kind="hollow"
autoAlign
size="2xs"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
<Slug
kind="hollow"
autoAlign
size="xs"
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
/>
</div>
<div className="slug-container">
<Slug kind="inline" size="sm" />
<Slug kind="inline" size="md" />
<Slug kind="inline" size="lg" />
</div>
<div className="slug-container">
<Slug kind="inline" size="sm" slugContent="Text goes here" />
<Slug kind="inline" size="md" slugContent="Text goes here" />
<Slug kind="inline" size="lg" slugContent="Text goes here" />
</div>
<div className="slug-container">
<Slug kind="inline" dotType="hollow" size="sm" />
<Slug kind="inline" dotType="hollow" size="md" />
<Slug kind="inline" dotType="hollow" size="lg" />
</div>
<div className="slug-container">
<Slug
kind="inline"
dotType="hollow"
size="sm"
slugContent="Text goes here"
/>
<Slug
kind="inline"
dotType="hollow"
size="md"
slugContent="Text goes here"
/>
<Slug
kind="inline"
dotType="hollow"
size="lg"
slugContent="Text goes here"
/>
</div>
</>
);

export const Playground = (args) => (
<Slug
autoAlign
slugContent="Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua. Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut fsil labore et dolore magna aliqua."
{...args}
/>
);
10 changes: 10 additions & 0 deletions packages/react/src/components/Slug/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* 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 Slug from './Slug';

export default Slug;
export { Slug };
9 changes: 9 additions & 0 deletions packages/react/src/components/Slug/slug-story.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.slug-container {
display: flex;
margin-bottom: 6rem;
align-items: flex-start;

& > * {
margin-left: 2rem;
}
}
Loading
Loading