Skip to content

Commit 5354d37

Browse files
Merge pull request #28 from linked-planet/dev
Dev
2 parents 8673738 + b21d444 commit 5354d37

40 files changed

+2245
-1584
lines changed

biome.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
"organizeImports": { "enabled": true },
1313
"linter": {
1414
"enabled": true,
15-
"rules": { "recommended": true },
15+
"rules": {
16+
"recommended": true,
17+
"complexity": {
18+
"noForEach": "off"
19+
}
20+
},
1621
"ignore": [
1722
"node_modules",
1823
"dist",
@@ -30,7 +35,6 @@
3035
"formatter": {
3136
"jsxQuoteStyle": "double",
3237
"quoteProperties": "asNeeded",
33-
"trailingComma": "all",
3438
"semicolons": "asNeeded",
3539
"arrowParentheses": "always",
3640
"bracketSpacing": true,

library/src/components/Button.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export type ButtonProps = {
5656
| "onTouchCancel"
5757
| "title"
5858
| "aria-label"
59+
| "tabIndex"
60+
| "aria-disabled"
5961
>
6062

6163
const ButtonStyles: { [style in ButtonAppearance]: string } = {

library/src/components/Flag.tsx

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ export type FlagProps = {
2020
title: string
2121
description: string | JSX.Element
2222
appearance?: FlagAppearance
23-
inverted?: boolean
23+
type?: "default" | "inverted" | "pale"
2424
icon?: JSX.Element
2525
actions?: FlagActionType[]
2626
style?: CSSProperties
27+
className?: string
2728
id?: string
2829
testId?: string
2930
}
@@ -36,7 +37,7 @@ export type FlagActionType = {
3637
testId?: string | undefined
3738
}
3839

39-
const defaultStyle = "bg-text text-text-inverse"
40+
const defaultStyle = "bg-neutral-full text-text-inverse"
4041
const warningStyle = "bg-warning-bold text-text-inverse"
4142
const errorStyle = "bg-danger-bold text-text-inverse"
4243
const successStyle = "bg-success-bold text-text-inverse"
@@ -65,11 +66,28 @@ export const FlagInvertedStyles: {
6566
information: informationInvertedStyle,
6667
} as const
6768

68-
const defaultIconStyle = "text-text"
69-
const warningIconStyle = "text-warning-bold"
70-
const errorIconStyle = "text-danger-bold"
71-
const successIconStyle = "text-success-bold"
72-
const informationIconStyle = "text-information-bold"
69+
const paleDefaultStyle = "bg-neutral text-text border-border"
70+
const paleWarningStyle = "bg-warning text-warning-text border-warning-border"
71+
const paleErrorStyle = "bg-danger text-danger-text border-danger-border"
72+
const paleSuccessStyle = "bg-success text-success-text border-success-border"
73+
const paleInformationStyle =
74+
"bg-information text-information-text border-information-border"
75+
76+
export const FlagPaleStyles: {
77+
[style in FlagAppearance]: string
78+
} = {
79+
default: paleDefaultStyle,
80+
warning: paleWarningStyle,
81+
error: paleErrorStyle,
82+
success: paleSuccessStyle,
83+
information: paleInformationStyle,
84+
} as const
85+
86+
const defaultIconStyle = "text-icon"
87+
const warningIconStyle = "text-warning-icon"
88+
const errorIconStyle = "text-danger-icon"
89+
const successIconStyle = "text-success-icon"
90+
const informationIconStyle = "text-information-icon"
7391

7492
const IconStyles: { [style in FlagAppearance]: string } = {
7593
default: defaultIconStyle,
@@ -80,10 +98,10 @@ const IconStyles: { [style in FlagAppearance]: string } = {
8098
} as const
8199

82100
const defaultIconInvertedStyle = "text-text"
83-
const warningIconInvertedStyle = "text-warning-bold-hovered"
84-
const errorIconInvertedStyle = "text-danger-bold-hovered"
85-
const successIconInvertedStyle = "text-success-bold-hovered"
86-
const informationIconInvertedStyle = "text-information-bold-hovered"
101+
const warningIconInvertedStyle = "text-warning-icon"
102+
const errorIconInvertedStyle = "text-danger-icon"
103+
const successIconInvertedStyle = "text-success-icon"
104+
const informationIconInvertedStyle = "text-information-icon"
87105

88106
const IconInvertedStyles: { [style in FlagAppearance]: string } = {
89107
default: defaultIconInvertedStyle,
@@ -95,14 +113,15 @@ const IconInvertedStyles: { [style in FlagAppearance]: string } = {
95113

96114
function FlagIcon({
97115
appearance = "default",
98-
invert,
116+
type,
99117
}: {
100118
appearance?: FlagAppearance
101-
invert: boolean
119+
type: "default" | "inverted" | "pale"
102120
}) {
103-
const iconStyle = invert
104-
? IconStyles[appearance]
105-
: IconInvertedStyles[appearance]
121+
const iconStyle =
122+
type === "default" || type === "pale"
123+
? IconStyles[appearance]
124+
: IconInvertedStyles[appearance]
106125

107126
switch (appearance) {
108127
case "default": {
@@ -146,18 +165,22 @@ export function Flag({
146165
description,
147166
icon,
148167
appearance = "default",
149-
inverted = false,
168+
type = "default",
150169
actions,
151170
style,
171+
className,
152172
id,
153173
testId,
154174
}: FlagProps) {
155-
const appStyle = inverted
156-
? FlagInvertedStyles[appearance]
157-
: FlagStyles[appearance]
175+
const appStyle =
176+
type === "default"
177+
? FlagStyles[appearance]
178+
: type === "inverted"
179+
? FlagInvertedStyles[appearance]
180+
: FlagPaleStyles[appearance]
158181

159182
if (!icon) {
160-
icon = <FlagIcon appearance={appearance} invert={inverted} />
183+
icon = <FlagIcon appearance={appearance} type={type} />
161184
}
162185

163186
return (
@@ -169,8 +192,9 @@ export function Flag({
169192
className={twMerge(
170193
appStyle,
171194
`grid gap-4 rounded-sm p-4 shadow-md ${
172-
inverted ? "border" : ""
195+
type === "inverted" || type === "pale" ? "border" : ""
173196
}`,
197+
className,
174198
)}
175199
id={id}
176200
data-testid={testId}

library/src/components/Pagination.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ function PaginationPageHandler<P extends string | number>({
8989
className,
9090
style,
9191
pageLabel,
92+
pageButtonClassName,
93+
pageButtonStyle,
9294
}: {
9395
pages: P[]
9496
currentPage?: P
@@ -104,6 +106,8 @@ function PaginationPageHandler<P extends string | number>({
104106
pageLabel?: string
105107
className?: string
106108
style?: React.CSSProperties
109+
pageButtonClassName?: string
110+
pageButtonStyle?: React.CSSProperties
107111
}) {
108112
const [_currentPage, setCurrentPage] = useState(
109113
currentPage ?? defaultPage ?? pages[0],
@@ -185,11 +189,14 @@ function PaginationPageHandler<P extends string | number>({
185189
<li>
186190
<button
187191
disabled={currentIdx <= 0}
188-
className={`flex h-8 w-8 select-none items-center justify-center rounded p-1.5 ${
189-
currentIdx > 0
190-
? "hover:bg-neutral-hovered active:bg-neutral-pressed text-text"
191-
: "text-disabled-text"
192-
}`}
192+
className={twMerge(
193+
`flex h-8 w-8 select-none items-center justify-center rounded p-1.5 ${
194+
currentIdx > 0
195+
? "hover:bg-neutral-hovered active:bg-neutral-pressed text-text"
196+
: "text-disabled-text"
197+
}`,
198+
pageButtonClassName,
199+
)}
193200
onClick={() => {
194201
const currentIndex = pages.indexOf(_currentPage)
195202
setCurrentPage(pages[currentIndex - 1])
@@ -212,9 +219,9 @@ function PaginationPageHandler<P extends string | number>({
212219
<button
213220
className={twMerge(
214221
"flex h-8 min-w-8 select-none items-center justify-center rounded p-1.5",
215-
page === _currentPage
216-
? "bg-selected text-selected-text-inverse"
217-
: "hover:bg-neutral-hovered active:bg-neutral-pressed",
222+
"data-[current=true]:bg-selected data-[current=true]:text-selected-text-inverse",
223+
"hover:bg-neutral-hovered active:bg-neutral-pressed",
224+
pageButtonClassName,
218225
)}
219226
onClick={() => {
220227
const currentIndex = pages.indexOf(
@@ -239,6 +246,8 @@ function PaginationPageHandler<P extends string | number>({
239246
aria-current={
240247
page === _currentPage ? "page" : undefined
241248
}
249+
style={pageButtonStyle}
250+
data-current={page === _currentPage}
242251
>
243252
{page}
244253
</button>
@@ -254,11 +263,14 @@ function PaginationPageHandler<P extends string | number>({
254263
</li>
255264
))}
256265
<button
257-
className={`flex h-8 w-8 select-none items-center justify-center rounded p-1.5 ${
258-
currentIdx < pages.length - 1
259-
? "hover:bg-neutral-hovered active:bg-neutral-pressed text-text"
260-
: "text-disabled-text"
261-
}`}
266+
className={twMerge(
267+
`flex h-8 w-8 select-none items-center justify-center rounded p-1.5 ${
268+
currentIdx < pages.length - 1
269+
? "hover:bg-neutral-hovered active:bg-neutral-pressed text-text"
270+
: "text-disabled-text"
271+
}`,
272+
pageButtonClassName,
273+
)}
262274
onClick={() => {
263275
const _currentIndex = pages.indexOf(_currentPage)
264276
setCurrentPage(pages[_currentIndex + 1])
@@ -270,6 +282,7 @@ function PaginationPageHandler<P extends string | number>({
270282
aria-label={nextLabel}
271283
aria-disabled={currentIdx >= pages.length - 1}
272284
type="button"
285+
style={pageButtonStyle}
273286
>
274287
<IconSizeHelper>
275288
<ChevronRightLargeIcon size="medium" label="" />
@@ -301,6 +314,8 @@ export function Pagination<P extends string | number>({
301314
previousLabel = "Previous Page",
302315
nextLabel = "Next Page",
303316
pageLabel = "",
317+
pageButtonClassName,
318+
pageButtonStyle,
304319
...pageSizeSelectorProps
305320
}: {
306321
totalPages?: number
@@ -326,6 +341,8 @@ export function Pagination<P extends string | number>({
326341
pageLabel?: string
327342
className?: string
328343
style?: React.CSSProperties
344+
pageButtonClassName?: string
345+
pageButtonStyle?: React.CSSProperties
329346
}) {
330347
const _pages = useMemo(() => {
331348
if (pages) return pages
@@ -359,6 +376,8 @@ export function Pagination<P extends string | number>({
359376
nextLabel={nextLabel}
360377
label={label}
361378
pageLabel={pageLabel}
379+
pageButtonClassName={pageButtonClassName}
380+
pageButtonStyle={pageButtonStyle}
362381
/>
363382
</div>
364383
{!hidePageSize && (

library/src/components/ToastFlag.tsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import {
1515
type FlagActionType,
1616
type FlagAppearance,
1717
FlagInvertedStyles,
18+
FlagPaleStyles,
1819
type FlagProps,
1920
FlagStyles,
2021
} from "./Flag"
2122

22-
type ToastFlagProps = FlagProps & ToastOptions
23+
type ToastFlagProps = Omit<FlagProps, "type"> &
24+
Omit<ToastOptions, "type"> & { flagType?: FlagProps["type"] }
2325

2426
const defaultSettings: ToastOptions = {
2527
position: "bottom-right",
@@ -84,20 +86,33 @@ function CloseButton({
8486
)
8587
}
8688

87-
export function ToastFlagContainer(props: ToastContainerProps) {
89+
export function ToastFlagContainer(
90+
props: ToastContainerProps & { toastWidth?: number | string },
91+
) {
92+
if (props.toastWidth) {
93+
// get ":root"
94+
const root = document.documentElement
95+
root.style.setProperty(
96+
"--toastify-toast-width",
97+
props.toastWidth.toString(),
98+
)
99+
}
100+
88101
const portalNode = getPortal(portalDivId)
89102
return <>{createPortal(<ToastContainer {...props} />, portalNode)}</>
90103
}
91104

92105
export function showFlagExtended({
93106
style,
94107
appearance = "default",
95-
inverted = false,
108+
className: _className,
109+
flagType = "inverted",
96110
...props
97111
}: ToastFlagProps) {
98-
const progressClassName = inverted
99-
? progressInvertedStyles[appearance]
100-
: progressStyles[appearance]
112+
const progressClassName =
113+
flagType === "inverted" || flagType === "pale"
114+
? progressInvertedStyles[appearance]
115+
: progressStyles[appearance]
101116

102117
const flagStyle: CSSProperties = {
103118
boxShadow: "unset",
@@ -107,22 +122,31 @@ export function showFlagExtended({
107122
fontFamily: "unset",
108123
}
109124

110-
const className = inverted
111-
? FlagInvertedStyles[appearance]
112-
: FlagStyles[appearance]
125+
const className = twMerge(
126+
flagType === "inverted"
127+
? FlagInvertedStyles[appearance]
128+
: flagType === "pale"
129+
? FlagPaleStyles[appearance]
130+
: FlagStyles[appearance],
131+
_className,
132+
)
113133

114134
toast(
115135
<Flag
116136
icon={props.icon}
117137
appearance={appearance}
118-
inverted={inverted}
138+
type={flagType}
119139
style={flagStyle}
140+
className="bottom-0 bg-transparent p-0 shadow-none"
120141
{...props}
121142
/>,
122143
{
123144
...defaultSettings,
124145
closeButton: (p: CloseButtonProps) => (
125-
<CloseButton inverted={inverted} {...p} />
146+
<CloseButton
147+
inverted={flagType === "inverted" || flagType === "pale"}
148+
{...p}
149+
/>
126150
),
127151
...props,
128152
style,
@@ -131,7 +155,12 @@ export function showFlagExtended({
131155
"--toastify-color-progress-light": "invalid",
132156
} as CSSProperties,
133157
progressClassName: progressClassName,
134-
className: twMerge(className, inverted ? "border" : undefined),
158+
className: twMerge(
159+
className,
160+
flagType === "inverted" || flagType === "pale"
161+
? "border border-solid"
162+
: undefined,
163+
),
135164
},
136165
)
137166
}
@@ -146,12 +175,12 @@ type SimpleFlagProps = {
146175
autoClose?: false | number
147176
position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"
148177
actions?: FlagActionType[]
178+
flagType?: FlagProps["type"]
149179
}
150180

151181
export function showFlag(props: SimpleFlagProps) {
152182
showFlagExtended({
153183
...props,
154-
inverted: true,
155184
})
156185
}
157186

0 commit comments

Comments
 (0)