Skip to content

Commit

Permalink
feat: move AddButton component to ui-kit
Browse files Browse the repository at this point in the history
JIRA: F1-437
risk: low
  • Loading branch information
scavnickyj committed Jul 2, 2024
1 parent 732f379 commit c29fbe8
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React, { useCallback, useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { Button, Dialog, Hyperlink, Typography } from "@gooddata/sdk-ui-kit";
import { AddButton, Button, Dialog, Hyperlink, Typography } from "@gooddata/sdk-ui-kit";
import { IAutomationMetadataObject } from "@gooddata/sdk-model";

import { ScheduledEmails } from "./components/ScheduledEmailsList.js";
Expand All @@ -15,7 +15,6 @@ import {
useDashboardSelector,
} from "../../../model/index.js";
import { messages } from "../../../locales.js";
import { CreateButton } from "./components/CreateButton.js";

/**
* @alpha
Expand Down Expand Up @@ -72,10 +71,10 @@ export const ScheduledEmailManagementDialog: React.FC<IScheduledEmailManagementD
<Typography tagName="h3">
<FormattedMessage id={messages.scheduleManagementListTitle.id!} />
</Typography>
<CreateButton
<AddButton
onClick={onAdd}
isDisabled={isLoadingScheduleData || automations.length >= maxAutomations}
titleId={messages.scheduleManagementCreate.id!}
title={<FormattedMessage id={messages.scheduleManagementCreate.id!} />}
/>
</div>
<ScheduledEmails
Expand Down

This file was deleted.

8 changes: 6 additions & 2 deletions libs/sdk-ui-dashboard/styles/scss/scheduled_mail.scss
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ $dialog-padding: 20px;
> .gd-label {
height: 30px;
line-height: 30px;
margin-bottom: 5px;
}

.gd-attachment-config-button {
Expand Down Expand Up @@ -369,14 +368,18 @@ $dialog-padding: 20px;

@media #{kit-variables.$small-only} {
width: calc(100vw - 20px);
height: 100vh;
height: 90vh;
max-height: none;
}

.gd-scheduled-email-management-dialog-title {
display: flex;
margin-bottom: 10px;

.gd-dialog-header {
margin: 0;
}

> h3 {
color: var(--gd-modal-title-color, kit-variables.$gd-color-dark);
}
Expand Down Expand Up @@ -848,6 +851,7 @@ $dialog-padding: 20px;
}

.gd-divider-with-margin {
margin-top: 0;
margin-bottom: $vertical-space;
}

Expand Down
19 changes: 19 additions & 0 deletions libs/sdk-ui-kit/api/sdk-ui-kit.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export type ActionType = "LinkButton" | "Button" | "Switcher";
// @internal (undocumented)
export function activateHeaderMenuItems(items: IHeaderMenuItem[][], ids: Array<string>): IHeaderMenuItem[][];

// @internal (undocumented)
export const AddButton: React_2.FC<IAddButtonProps>;

// @internal (undocumented)
export const AddGranteeBase: React_2.FC<IAddGranteeBaseProps>;

Expand Down Expand Up @@ -739,6 +742,22 @@ export const HubspotConversionTouchPointDialog: React_2.FC<IHubspotConversionTou
// @internal
export const Hyperlink: React_2.FC<IHyperlinkProps>;

// @internal (undocumented)
export interface IAddButtonProps {
// (undocumented)
className?: string;
// (undocumented)
isDisabled?: boolean;
// (undocumented)
onClick?: () => void;
// (undocumented)
title: JSX.Element;
// (undocumented)
tooltip?: JSX.Element;
// (undocumented)
tooltipAlignPoints?: IAlignPoint[];
}

// @internal (undocumented)
export interface IAddGranteeBaseProps {
// (undocumented)
Expand Down
76 changes: 76 additions & 0 deletions libs/sdk-ui-kit/src/AddButton/AddButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// (C) 2024 GoodData Corporation

import React, { useCallback } from "react";
import cx from "classnames";
import { BubbleHoverTrigger } from "../Bubble/BubbleHoverTrigger.js";
import { Button } from "../Button/Button.js";
import { Bubble } from "../Bubble/Bubble.js";
import { IAlignPoint } from "../typings/positioning.js";

const defaultTooltipAlignPoints = [{ align: "cr cl" }, { align: "cl cr" }];

/**
* @internal
*/
export interface IAddButtonProps {
title: JSX.Element;
isDisabled?: boolean;
onClick?: () => void;
tooltip?: JSX.Element;
tooltipAlignPoints?: IAlignPoint[];
className?: string;
}

/**
* @internal
*/
export const AddButton: React.FC<IAddButtonProps> = (props) => {
const {
title,
isDisabled,
onClick,
tooltip,
tooltipAlignPoints = defaultTooltipAlignPoints,
className,
} = props;

const buttonClassNames = cx(
{
disabled: isDisabled,
},
"gd-button-link",
"gd-icon-plus",
"s-add-button",
className,
);

const handleClick = useCallback(
(e: React.MouseEvent) => {
e.preventDefault();
if (isDisabled) {
return;
}
onClick?.();
},
[isDisabled, onClick],
);

if (!tooltip) {
return (
<Button className={buttonClassNames} onClick={handleClick}>
{title}
</Button>
);
}

return (
<BubbleHoverTrigger showDelay={0} hideDelay={0}>
<Button className={buttonClassNames} onClick={handleClick}>
{title}
</Button>
<Bubble className="bubble-primary" alignPoints={tooltipAlignPoints}>
{tooltip}
</Bubble>
</BubbleHoverTrigger>
);
};
3 changes: 3 additions & 0 deletions libs/sdk-ui-kit/src/AddButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// (C) 2024 GoodData Corporation

export { AddButton, IAddButtonProps } from "./AddButton.js";
1 change: 1 addition & 0 deletions libs/sdk-ui-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ export * from "./TextAreaWithSubmit/index.js";
export * from "./SeparatorLine/index.js";
export * from "./RichText/index.js";
export * from "./RecurrenceForm/index.js";
export * from "./AddButton/index.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// (C) 2024 GoodData Corporation

import React from "react";
import { storiesOf } from "../../../_infra/storyRepository.js";
import { UiKit } from "../../../_infra/storyGroups.js";
import { wrapWithTheme } from "../../themeWrapper.js";
import { AddButton } from "@gooddata/sdk-ui-kit";
import { action } from "@storybook/addon-actions";

const onClick = () => {
action("onClick");
};

const AddButtonTest = () => {
return (
<div className="library-component screenshot-target">
<h4>Default</h4>
<AddButton title={<>Create</>} onClick={onClick} />

<h4>Disabled</h4>
<AddButton title={<>Can&apos;t touch this</>} isDisabled={true} onClick={onClick} />

<h4>With tooltip</h4>
<AddButton title={<>Hover</>} tooltip={<>Some information here!</>} onClick={onClick} />
</div>
);
};

storiesOf(`${UiKit}/AddButton`)
.add("full-featured", () => <AddButtonTest />, { screenshot: true })
.add("themed", () => wrapWithTheme(<AddButtonTest />), { screenshot: true });

0 comments on commit c29fbe8

Please sign in to comment.