Skip to content

Commit 5bed176

Browse files
committed
-work on atlassian design tailwind design system,
-new: buttons -rework of flag/toast flag and inline messages
1 parent a1bfd8b commit 5bed176

File tree

19 files changed

+1359
-918
lines changed

19 files changed

+1359
-918
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"plugin:@atlaskit/design-system/recommended",
2222
"plugin:react/recommended",
2323
"plugin:react-hooks/recommended",
24-
"prettier"
24+
"prettier",
25+
"plugin:tailwindcss/recommended"
2526
],
2627
"settings": {
2728
"react": {

.prettierrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

library/src/components/Button.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React, { CSSProperties } from "react"
2+
import { twMerge } from "tailwind-merge"
3+
import { InteractiveAppearance, InteractiveStyles } from "../utils/colors"
4+
import Spinner from '@atlaskit/spinner'
5+
6+
7+
export type ButtonProps = {
8+
appearance?: InteractiveAppearance
9+
label?: string
10+
title?: string
11+
iconBefore?: React.ReactNode
12+
iconAfter?: React.ReactNode
13+
onClick: () => void
14+
children?: React.ReactNode
15+
style?: CSSProperties
16+
className?: string
17+
}
18+
19+
export const Button = ({
20+
label = "",
21+
title = "",
22+
appearance = "default",
23+
iconBefore,
24+
iconAfter,
25+
style,
26+
onClick,
27+
children,
28+
className,
29+
}: ButtonProps) => {
30+
return (
31+
<button
32+
title={title}
33+
aria-label={label}
34+
onClick={onClick}
35+
style={style}
36+
className={twMerge(InteractiveStyles[appearance], "px-3 py-1 rounded flex justify-center items-center relative gap-1", className)}
37+
>
38+
{iconBefore}
39+
{children}
40+
{iconAfter}
41+
</button>
42+
)
43+
}
44+
45+
46+
export const LoadingButton = ({
47+
isLoading = false,
48+
children,
49+
...props
50+
}: ButtonProps & { isLoading: boolean }) => {
51+
return (
52+
<Button
53+
{...props}
54+
>
55+
<div className={isLoading ? "opacity-0" : undefined}>
56+
{children}
57+
</div>
58+
{ isLoading &&
59+
<div
60+
className="absolute inset-0 flex items-center justify-center"
61+
>
62+
<Spinner />
63+
</div>
64+
}
65+
</Button>
66+
)
67+
}
68+
69+
export const ButtonGroup = ({ children }: { children: React.ReactNode }) => {
70+
return (
71+
<div className="inline-flex gap-1">
72+
{children}
73+
</div>
74+
)
75+
}

library/src/components/Flag.tsx

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import Tick from "@atlaskit/icon/glyph/check-circle"
44
import Error from "@atlaskit/icon/glyph/error"
55
import Info from "@atlaskit/icon/glyph/info"
66
import Warning from "@atlaskit/icon/glyph/warning"
7-
import DiscoverFilledIcon from "@atlaskit/icon/glyph/discover-filled"
87

98
import { token } from "@atlaskit/tokens"
10-
import { Appearance, getAppearanceColors } from "../utils/colors"
11-
import { N0 } from "@atlaskit/theme/colors"
9+
import { getAppearanceColors, InteractiveAppearance, InteractiveStyles, InteractiveInvertedStyles } from "../utils/colors"
10+
import { twMerge } from "tailwind-merge"
1211

1312
export type FlagProps = {
1413
title: string
1514
description: string | JSX.Element
16-
appearance?: Appearance
15+
appearance?: InteractiveAppearance
1716
invert?: boolean
1817
icon?: JSX.Element
1918
actions?: FlagActionType[]
@@ -32,9 +31,10 @@ function FlagIcon({
3231
appearance,
3332
invert,
3433
}: {
35-
appearance?: Appearance
34+
appearance?: InteractiveAppearance
3635
invert: boolean
3736
}) {
37+
3838
const { primaryColor, secondaryColor } = getAppearanceColors(
3939
invert,
4040
appearance,
@@ -77,20 +77,12 @@ function FlagIcon({
7777
/>
7878
)
7979
}
80-
case "discovery": {
81-
return (
82-
<DiscoverFilledIcon
83-
label="Discovery"
84-
primaryColor={primaryColor}
85-
secondaryColor={secondaryColor}
86-
/>
87-
)
88-
}
8980
}
9081

9182
return null
9283
}
9384

85+
9486
export function Flag({
9587
title,
9688
description,
@@ -100,63 +92,42 @@ export function Flag({
10092
actions,
10193
style,
10294
}: FlagProps) {
103-
const { primaryColor, textColor, secondaryColor } = getAppearanceColors(
104-
invert ?? true,
105-
appearance,
106-
)
95+
const appStyle = invert ? InteractiveInvertedStyles[appearance ?? "default"] : InteractiveStyles[appearance ?? "default"]
96+
10797

10898
if (!icon) {
10999
icon = <FlagIcon appearance={appearance} invert={!invert} />
110100
}
111101

112-
const backgroundColor = invert
113-
? token("elevation.surface.overlay", N0)
114-
: primaryColor
115-
116102
return (
117103
<div
118104
style={{
119-
display: "grid",
120105
gridTemplateColumns: "auto 1fr",
121-
gap: "1rem",
122-
padding: token("space.200", "1rem"),
123-
borderRadius: token("border.radius.100", "0.25rem"),
124-
backgroundColor,
125-
color: textColor,
126-
border: `1px solid ${secondaryColor}`,
127106
boxShadow: token(
128107
"elevation.shadow.overlay",
129108
"0px 8px 12px #091e423f, 0px 0px 1px #091e424f",
130109
),
131110
...style,
132111
}}
112+
className={twMerge(appStyle, "grid gap-4 rounded-sm p-4 border-[1px]")}
133113
>
134114
{icon && (
135115
<div>
136116
<p
137-
style={{
138-
display: "flex",
139-
justifyItems: "center",
140-
alignItems: "center",
141-
}}
117+
className="flex items-center justify-center"
142118
>
143119
{icon}
144120
</p>
145121
</div>
146122
)}
147123
<div>
148-
<div className="font-bold mb-2">{title}</div>
124+
<div className="mb-2 font-bold">{title}</div>
149125
<div>{description}</div>
150126
<div>
151127
{actions?.map((action, i) => (
152128
<a
153129
key={i}
154-
style={{
155-
display: "inline-block",
156-
cursor: "pointer",
157-
marginTop: "0.75rem",
158-
fontSize: "small",
159-
}}
130+
className="mt-3 inline-block cursor-pointer text-sm"
160131
onClick={action.onClick}
161132
href={action.href}
162133
target={action.target}

library/src/components/ToastFlag.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ import CrossIcon from "@atlaskit/icon/glyph/cross"
1010

1111
import { token } from "@atlaskit/tokens"
1212
import { Flag, FlagActionType, FlagProps } from "./Flag"
13-
import { getAppearanceColors } from "../utils/colors"
14-
import type { Appearance } from "../utils/colors"
13+
import {
14+
getAppearanceColors,
15+
InteractiveAppearance,
16+
InteractiveInvertedStyles,
17+
InteractiveStyles,
18+
} from "../utils/colors"
19+
import { twMerge } from "tailwind-merge"
1520

1621
type ToastFlagProps = FlagProps & ToastOptions
1722

@@ -39,7 +44,7 @@ const defaultSettings: ToastOptions = {
3944
export function showFlagExtended({
4045
style,
4146
progressStyle,
42-
appearance,
47+
appearance = "default",
4348
invert = false,
4449
...props
4550
}: ToastFlagProps) {
@@ -57,18 +62,20 @@ export function showFlagExtended({
5762
boxShadow: "unset",
5863
padding: "unset",
5964
border: 0,
65+
background: "unset",
6066
}
6167

62-
const backgroundColor = invert
63-
? token("elevation.surface.overlay", N0)
64-
: primaryColor
68+
const className = invert
69+
? InteractiveInvertedStyles[appearance]
70+
: InteractiveStyles[appearance]
6571

66-
const toastStyle: CSSProperties = {
67-
backgroundColor,
68-
color: textColor,
69-
border: `1px solid ${secondaryColor}`,
70-
...style,
72+
// this is a hack, since the default UI element color have transparency, we reset it to "neutral"
73+
let additionalClassName: string = ""
74+
if (appearance === "default") {
75+
additionalClassName =
76+
"bg-surface hover:bg-surface-hovered active:bg-surface-pressed"
7177
}
78+
//
7279

7380
toast(
7481
<Flag
@@ -84,19 +91,20 @@ export function showFlagExtended({
8491
<CloseButton color={textColor} {...p} />
8592
),
8693
...props,
87-
style: toastStyle,
94+
style,
8895
progressStyle: progressStyleUsed,
96+
className: twMerge(className, "border-[1px]", additionalClassName),
8997
},
9098
)
9199
}
92100

93101
/**
94-
* Simeple flag is a version of FlagExtended without forwarding all the ToastOptions
102+
* Simple flag is a version of FlagExtended without forwarding all the ToastOptions
95103
*/
96104
type SimpleFlagProps = {
97105
title: string
98106
description: string | JSX.Element
99-
appearance?: Appearance
107+
appearance?: InteractiveAppearance
100108
autoClose?: false | number
101109
position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"
102110
actions?: FlagActionType[]
@@ -130,7 +138,3 @@ export function showInformationFlag(
130138
export function showWarningFlag(props: Omit<SimpleFlagProps, "appearance">) {
131139
showFlag({ ...props, appearance: "warning" })
132140
}
133-
134-
export function showDiscoveryFlag(props: Omit<SimpleFlagProps, "appearance">) {
135-
showFlag({ ...props, appearance: "discovery" })
136-
}

library/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from "./Collapsible"
77
export * from "./BookCard"
88
export * from "./ToastFlag"
99
export * from "./Flag"
10+
export * from "./Button"

0 commit comments

Comments
 (0)