Skip to content

Commit bba65eb

Browse files
authored
revert: Update custom dev pages to use light-dark method (#3896) (#3963)
1 parent 7d5b327 commit bba65eb

File tree

10 files changed

+747
-456
lines changed

10 files changed

+747
-456
lines changed

pages/alert/style-custom-types.page.tsx

Lines changed: 109 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import React from 'react';
3+
import React, { useRef } from 'react';
4+
5+
import { useCurrentMode } from '@cloudscape-design/component-toolkit/internal';
46

57
import { Alert as CloudscapeAlert, Button, SpaceBetween } from '~components';
68

@@ -66,6 +68,12 @@ interface CustomAlertProps {
6668
}
6769

6870
function CustomAlert({ children, type, dismissible, action }: CustomAlertProps) {
71+
const mode = useCurrentMode(useRef(document.body));
72+
const background = backgrounds[mode][type];
73+
const borderColor = borderColors[mode][type];
74+
const borderWidth = borderWidths[type];
75+
const color = colors[mode];
76+
const iconColor = iconColors[mode][type];
6977
return (
7078
<CloudscapeAlert
7179
dismissible={dismissible}
@@ -74,22 +82,26 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
7482
i18nStrings={i18nStrings}
7583
style={{
7684
root: {
77-
background: getBackground(type),
78-
borderColor: getBorderColor(type),
85+
background,
86+
borderColor,
7987
borderRadius: '8px',
80-
borderWidth: getBorderWidth(type),
81-
color: getColor(),
88+
borderWidth,
89+
color,
8290
focusRing: {
8391
borderColor: palette.red60,
8492
borderRadius: '4px',
8593
borderWidth: '2px',
8694
},
8795
},
8896
icon: {
89-
color: getIconColor(type),
97+
color: iconColor,
9098
},
9199
dismissButton: {
92-
color: getDismissButtonColor(type),
100+
color: {
101+
default: dismissButtonColors[mode][type].default,
102+
hover: dismissButtonColors[mode][type].hover,
103+
active: dismissButtonColors[mode][type].active,
104+
},
93105
focusRing: {
94106
borderColor: palette.red60,
95107
borderRadius: '4px',
@@ -103,72 +115,106 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
103115
);
104116
}
105117

106-
function getBackground(type: string) {
107-
const backgrounds = {
108-
info: `light-dark(${palette.blue80}, ${palette.blue40})`,
109-
success: `light-dark(${palette.green80}, ${palette.green20})`,
110-
error: `light-dark(${palette.red80}, ${palette.red30})`,
111-
warning: `light-dark(${palette.teal90}, ${palette.teal20})`,
112-
};
113-
return backgrounds[type as keyof typeof backgrounds];
114-
}
118+
const backgrounds = {
119+
light: {
120+
info: palette.blue80,
121+
success: palette.green80,
122+
error: palette.red80,
123+
warning: palette.teal90,
124+
},
125+
dark: {
126+
info: palette.blue40,
127+
success: palette.green20,
128+
error: palette.red30,
129+
warning: palette.teal20,
130+
},
131+
};
115132

116-
function getColor() {
117-
return `light-dark(${palette.neutral10}, ${palette.neutral100})`;
118-
}
133+
const colors = {
134+
light: palette.neutral10,
135+
dark: palette.neutral100,
136+
};
119137

120-
function getBorderColor(type: string) {
121-
const borderColors = {
122-
info: `light-dark(${palette.neutral80}, ${palette.neutral20})`,
123-
success: `light-dark(${palette.green80}, ${palette.green30})`,
124-
error: `light-dark(${palette.blue90}, ${palette.red60})`,
125-
warning: `light-dark(${palette.orange80}, ${palette.orange40})`,
126-
};
127-
return borderColors[type as keyof typeof borderColors];
128-
}
138+
const borderColors = {
139+
light: {
140+
info: palette.neutral80,
141+
success: palette.green80,
142+
error: palette.blue90,
143+
warning: palette.orange80,
144+
},
145+
dark: {
146+
info: palette.neutral20,
147+
success: palette.green30,
148+
error: palette.red60,
149+
warning: palette.orange40,
150+
},
151+
};
129152

130-
function getBorderWidth(type: string) {
131-
const borderWidths = {
132-
info: '4px',
133-
success: '0px',
134-
error: '6px',
135-
warning: '0px',
136-
};
137-
return borderWidths[type as keyof typeof borderWidths];
138-
}
153+
const borderWidths = {
154+
info: '4px',
155+
success: '0px',
156+
error: '6px',
157+
warning: '0px',
158+
};
139159

140-
function getIconColor(type: string) {
141-
const iconColors = {
142-
info: `light-dark(${palette.orange80}, ${palette.red30})`,
143-
success: `light-dark(${palette.red60}, ${palette.red60})`,
144-
error: `light-dark(${palette.blue80}, ${palette.blue40})`,
145-
warning: `light-dark(${palette.neutral10}, ${palette.neutral90})`,
146-
};
147-
return iconColors[type as keyof typeof iconColors];
148-
}
160+
const iconColors = {
161+
light: {
162+
info: palette.orange80,
163+
success: palette.red60,
164+
error: palette.blue80,
165+
warning: palette.neutral10,
166+
},
167+
dark: {
168+
info: palette.red30,
169+
success: palette.red60,
170+
error: palette.blue40,
171+
warning: palette.neutral90,
172+
},
173+
};
149174

150-
function getDismissButtonColor(type: string) {
151-
const dismissButtonColors = {
175+
const dismissButtonColors = {
176+
light: {
152177
info: {
153-
default: `light-dark(${palette.green60}, ${palette.neutral40})`,
154-
hover: `light-dark(${palette.neutral80}, ${palette.neutral20})`,
155-
active: `light-dark(${palette.neutral90}, ${palette.neutral10})`,
178+
default: palette.green60,
179+
hover: palette.neutral80,
180+
active: palette.neutral90,
156181
},
157182
success: {
158-
default: `light-dark(${palette.green60}, ${palette.green30})`,
159-
hover: `light-dark(${palette.green80}, ${palette.green20})`,
160-
active: `light-dark(${palette.green90}, ${palette.green10})`,
183+
default: palette.green60,
184+
hover: palette.green80,
185+
active: palette.green90,
161186
},
162187
error: {
163-
default: `light-dark(${palette.red60}, ${palette.red60})`,
164-
hover: `light-dark(${palette.red60}, ${palette.red20})`,
165-
active: `light-dark(${palette.red80}, ${palette.red10})`,
188+
default: palette.red60,
189+
hover: palette.red60,
190+
active: palette.red80,
166191
},
167192
warning: {
168-
default: `light-dark(${palette.orange60}, ${palette.orange40})`,
169-
hover: `light-dark(${palette.orange80}, ${palette.orange20})`,
170-
active: `light-dark(${palette.orange90}, ${palette.orange10})`,
193+
default: palette.orange60,
194+
hover: palette.orange80,
195+
active: palette.orange90,
171196
},
172-
};
173-
return dismissButtonColors[type as keyof typeof dismissButtonColors];
174-
}
197+
},
198+
dark: {
199+
info: {
200+
default: palette.neutral40,
201+
hover: palette.neutral20,
202+
active: palette.neutral10,
203+
},
204+
success: {
205+
default: palette.green30,
206+
hover: palette.green20,
207+
active: palette.green10,
208+
},
209+
error: {
210+
default: palette.red60,
211+
hover: palette.red20,
212+
active: palette.red10,
213+
},
214+
warning: {
215+
default: palette.orange40,
216+
hover: palette.orange20,
217+
active: palette.orange10,
218+
},
219+
},
220+
};
Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import React from 'react';
3+
import React, { useRef } from 'react';
4+
5+
import { useCurrentMode } from '@cloudscape-design/component-toolkit/internal';
46

57
import { Badge as CloudscapeBadge, SpaceBetween } from '~components';
68

@@ -29,15 +31,20 @@ interface CustomBadgeProps {
2931
}
3032

3133
function CustomBadge({ children, colorTheme }: CustomBadgeProps) {
34+
const mode = useCurrentMode(useRef(document.body));
35+
const background = backgrounds[mode][colorTheme];
36+
const borderColor = borderColors[mode][colorTheme];
37+
const borderWidth = borderWidths[colorTheme];
38+
const color = colors[mode];
3239
return (
3340
<CloudscapeBadge
3441
style={{
3542
root: {
36-
background: getBackground(colorTheme),
37-
borderColor: getBorderColor(colorTheme),
43+
background,
44+
borderColor,
3845
borderRadius: '8px',
39-
color: getColor(),
40-
borderWidth: getBorderWidth(colorTheme),
46+
color,
47+
borderWidth,
4148
paddingBlock: '8px',
4249
paddingInline: '12px',
4350
},
@@ -48,42 +55,54 @@ function CustomBadge({ children, colorTheme }: CustomBadgeProps) {
4855
);
4956
}
5057

51-
function getBackground(colorTheme: string) {
52-
const backgrounds = {
53-
blue: `light-dark(${palette.blue80}, ${palette.blue40})`,
54-
critical: `light-dark(${palette.red80}, ${palette.red30})`,
55-
high: `light-dark(${palette.red60}, ${palette.red30})`,
56-
medium: `light-dark(${palette.green80}, ${palette.green20})`,
57-
low: `light-dark(${palette.teal90}, ${palette.teal20})`,
58-
neutral: `light-dark(${palette.neutral80}, ${palette.neutral20})`,
59-
};
60-
return backgrounds[colorTheme as keyof typeof backgrounds];
61-
}
58+
const backgrounds = {
59+
light: {
60+
blue: palette.blue80,
61+
critical: palette.red80,
62+
high: palette.red60,
63+
medium: palette.green80,
64+
low: palette.teal90,
65+
neutral: palette.neutral80,
66+
},
67+
dark: {
68+
blue: palette.blue40,
69+
critical: palette.red30,
70+
high: palette.red30,
71+
medium: palette.green20,
72+
low: palette.teal20,
73+
neutral: palette.neutral20,
74+
},
75+
};
6276

63-
function getColor() {
64-
return 'light-dark(white, black)';
65-
}
77+
const colors = {
78+
light: 'white',
79+
dark: 'black',
80+
};
6681

67-
function getBorderColor(colorTheme: string) {
68-
const borderColors = {
69-
blue: `light-dark(${palette.neutral80}, ${palette.neutral20})`,
70-
critical: `light-dark(${palette.blue90}, ${palette.red60})`,
71-
high: `light-dark(${palette.red80}, ${palette.red10})`,
72-
medium: `light-dark(${palette.green80}, ${palette.green30})`,
73-
low: `light-dark(${palette.neutral80}, ${palette.neutral20})`,
74-
neutral: `light-dark(${palette.teal80}, ${palette.teal40})`,
75-
};
76-
return borderColors[colorTheme as keyof typeof borderColors];
77-
}
82+
const borderColors = {
83+
light: {
84+
blue: palette.neutral80,
85+
critical: palette.blue90,
86+
high: palette.red80,
87+
medium: palette.green80,
88+
low: palette.neutral80,
89+
neutral: palette.teal80,
90+
},
91+
dark: {
92+
blue: palette.neutral20,
93+
critical: palette.red60,
94+
high: palette.red10,
95+
medium: palette.green30,
96+
low: palette.neutral20,
97+
neutral: palette.teal40,
98+
},
99+
};
78100

79-
function getBorderWidth(colorTheme: string) {
80-
const borderWidths = {
81-
blue: '2px',
82-
critical: '4px',
83-
high: '0px',
84-
medium: '0px',
85-
low: '0px',
86-
neutral: '0px',
87-
};
88-
return borderWidths[colorTheme as keyof typeof borderWidths];
89-
}
101+
const borderWidths = {
102+
blue: '2px',
103+
critical: '4px',
104+
high: '0px',
105+
medium: '0px',
106+
low: '0px',
107+
neutral: '0px',
108+
};

0 commit comments

Comments
 (0)