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: add launch action for AILabel icon in icon library #4336

Merged
merged 3 commits into from
Oct 25, 2024
Merged
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
55 changes: 40 additions & 15 deletions src/components/SVGLibraries/shared/ActionBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef, useContext, useState } from 'react';
import { Code, Download } from '@carbon/icons-react';
import { Code, Download, Launch } from '@carbon/icons-react';
import { Button } from '@carbon/react';
import copy from 'copy-to-clipboard';
import cx from 'classnames';
Expand Down Expand Up @@ -46,6 +46,14 @@ const ActionBar = ({
copy(`<${moduleName} />`, { format: 'text/plain' });
};

// AILabel icon is customized to display a launch icon,
// linking to the React Storybook component, instead
// of the standard download action.
const shouldShowLaunchButton = name === 'ai-label';
const shouldShowDownloadButton = name !== 'ai-label';
const launchURL =
'https://react.carbondesignsystem.com/?path=/docs/components-ailabel--overview';

return (
<div
ref={actionBarRef}
Expand All @@ -54,23 +62,40 @@ const ActionBar = ({
className={cx(container, {
[hidden]: !isActionBarVisible,
})}>
<Button
kind="ghost"
size="small"
hasIconOnly
tooltipAlignment={tooltipAlignment}
tooltipPosition="top"
iconDescription="Download SVG"
renderIcon={Download}
onFocus={() => setIsActionBarVisible(true)}
onClick={handleDownload}
className={tooltip}
triggerClassName={trigger}
/>
{shouldShowLaunchButton && (
<Button
kind="ghost"
size="sm"
hasIconOnly
tooltipAlignment={tooltipAlignment}
tooltipPosition="top"
iconDescription="View component"
renderIcon={Launch}
onFocus={() => setIsActionBarVisible(true)}
href={launchURL}
className={tooltip}
triggerClassName={trigger}
/>
)}
{shouldShowDownloadButton && (
<Button
kind="ghost"
size="sm"
hasIconOnly
tooltipAlignment={tooltipAlignment}
tooltipPosition="top"
iconDescription="Download SVG"
renderIcon={Download}
onFocus={() => setIsActionBarVisible(true)}
onClick={handleDownload}
className={tooltip}
triggerClassName={trigger}
/>
)}
{shouldShowCopyButton && (
<Button
kind="ghost"
size="small"
size="sm"
hasIconOnly
tooltipAlignment={tooltipAlignment}
tooltipPosition="top"
Expand Down
2 changes: 0 additions & 2 deletions src/components/SVGLibraries/shared/ActionBar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
padding: 0;
border: 0;
background: transparent;
height: 32px;
width: 32px;
display: inline-flex;
justify-content: center;
align-items: center;
Expand Down
Loading