From 48ff856f56c50fbad321c807fcf38cb7a1a186b8 Mon Sep 17 00:00:00 2001 From: Nemes-Teodora <69592886+teodoranemes@users.noreply.github.com> Date: Wed, 22 Oct 2025 12:08:59 +0000 Subject: [PATCH 1/2] chore: Update custom dev pages to use light-dark method (#3896) Co-authored-by: Georgii Lobko (cherry picked from commit 4c800089d5ef7d693a9f1cf868d6401ee6497861) --- pages/alert/style-custom-types.page.tsx | 172 ++++------- pages/badge/style-custom-types.page.tsx | 101 +++--- .../button-group/style-custom-types.page.tsx | 292 +++++------------- pages/button/style-custom-types.page.tsx | 205 ++++-------- pages/button/style-permutations.page.tsx | 240 ++++++++------ pages/checkbox/style-custom.page.tsx | 31 +- pages/container/style-custom.page.tsx | 7 +- pages/link/style-custom-types.page.tsx | 92 ++---- pages/radio-group/style-custom.page.tsx | 35 +-- pages/toggle/style-custom.page.tsx | 28 +- 10 files changed, 456 insertions(+), 747 deletions(-) diff --git a/pages/alert/style-custom-types.page.tsx b/pages/alert/style-custom-types.page.tsx index 5c3973da4b..549e73b0f6 100644 --- a/pages/alert/style-custom-types.page.tsx +++ b/pages/alert/style-custom-types.page.tsx @@ -1,8 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import React, { useRef } from 'react'; - -import { useCurrentMode } from '@cloudscape-design/component-toolkit/internal'; +import React from 'react'; import { Alert as CloudscapeAlert, Button, SpaceBetween } from '~components'; @@ -68,12 +66,6 @@ interface CustomAlertProps { } function CustomAlert({ children, type, dismissible, action }: CustomAlertProps) { - const mode = useCurrentMode(useRef(document.body)); - const background = backgrounds[mode][type]; - const borderColor = borderColors[mode][type]; - const borderWidth = borderWidths[type]; - const color = colors[mode]; - const iconColor = iconColors[mode][type]; return ( ); } - -const backgrounds = { - light: { - blue: 'rgba(166, 222, 255, 0.91)', - green: 'rgba(152, 234, 182, 0.87)', - orange: 'rgba(223, 146, 91, 1)', - red: 'rgba(234, 91, 86, 0.52)', - teal: 'rgba(138, 237, 225, 0.76)', - nav: 'rgba(205, 202, 202, 0.85)', - }, - dark: { - blue: 'rgba(64, 123, 178, 0.8)', - green: 'rgba(34, 197, 94, 0.3)', - orange: 'rgba(204, 90, 9, 0.81)', - red: 'rgba(210, 60, 60, 0.63)', - teal: 'rgba(9, 188, 155, 0.71)', - nav: 'rgba(124, 122, 122, 1)', - }, -}; - -const borderColors = { - light: { - green: 'rgba(24, 146, 69, 0.4)', - red: 'rgba(239, 68, 68, 0.4)', - }, - dark: { - green: 'rgba(34, 197, 94, 0.6)', - red: 'rgba(239, 68, 68, 0.6)', - }, -}; - -const boxShadows = { - light: { - blue: '0 2px 12px rgba(59, 130, 246, 0.15)', - green: '0 2px 12px rgba(34, 197, 94, 0.15)', - orange: '0 2px 12px rgba(249, 115, 22, 0.15)', - red: '0 2px 12px rgba(239, 68, 68, 0.15)', - teal: '0 2px 12px rgba(20, 184, 166, 0.15)', - nav: '0 4px 20px rgba(0, 0, 0, 0.1)', - }, - dark: { - blue: '0 2px 12px rgba(59, 130, 246, 0.25)', - green: '0 2px 12px rgba(34, 197, 94, 0.25)', - orange: '0 2px 12px rgba(249, 115, 22, 0.25)', - red: '0 2px 12px rgba(239, 68, 68, 0.25)', - teal: '0 2px 12px rgba(20, 184, 166, 0.25)', - nav: '0 4px 20px rgba(255, 255, 255, 0.1)', - }, -}; - -const focusRingColors = { - light: { - blue: palette.blue80, - green: palette.green60, - orange: palette.orange60, - red: palette.red80, - teal: palette.teal80, - nav: palette.neutral80, - }, - dark: { - blue: palette.blue40, - green: palette.green30, - orange: palette.orange40, - red: palette.red30, - teal: palette.teal40, - nav: palette.neutral40, - }, -}; - -const itemColors = { - light: { - blue: { - active: palette.blue100, - default: palette.blue90, - hover: palette.blue100, - }, - green: { - active: palette.green100, - default: palette.green90, - hover: palette.green100, - }, - orange: { - active: palette.orange100, - default: palette.orange90, - hover: palette.orange100, - }, - red: { - active: palette.red100, - default: palette.red80, - hover: palette.red100, - }, - teal: { - active: palette.teal100, - default: palette.teal80, - hover: palette.teal100, - }, - nav: { - active: palette.neutral100, - default: palette.neutral80, - hover: palette.neutral100, - }, - disabled: palette.neutral60, - }, - dark: { - blue: { - active: palette.blue10, - default: palette.blue20, - hover: palette.blue10, - }, - green: { - active: palette.green10, - default: palette.green20, - hover: palette.green10, - }, - orange: { - active: palette.orange10, - default: palette.orange20, - hover: palette.orange10, - }, - red: { - active: palette.red10, - default: palette.red20, - hover: palette.red10, - }, - teal: { - active: palette.teal10, - default: palette.teal20, - hover: palette.teal10, - }, - nav: { - active: palette.neutral10, - default: palette.neutral20, - hover: palette.neutral10, - }, - disabled: palette.neutral40, - }, -}; +function getBoxShadow(colorTheme: string) { + const boxShadows = { + blue: `0 2px 12px light-dark(rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.25))`, + green: `0 2px 12px light-dark(rgba(34, 197, 94, 0.15), rgba(34, 197, 94, 0.25))`, + orange: `0 2px 12px light-dark(rgba(249, 115, 22, 0.15), rgba(249, 115, 22, 0.25))`, + red: `0 2px 12px light-dark(rgba(239, 68, 68, 0.15), rgba(239, 68, 68, 0.25))`, + teal: `0 2px 12px light-dark(rgba(20, 184, 166, 0.15),rgba(20, 184, 166, 0.25))`, + nav: `0 4px 20px light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1))`, + }; + return boxShadows[colorTheme as keyof typeof boxShadows]; +} diff --git a/pages/button/style-custom-types.page.tsx b/pages/button/style-custom-types.page.tsx index 7d3f4e5c03..05c0c5bf6b 100644 --- a/pages/button/style-custom-types.page.tsx +++ b/pages/button/style-custom-types.page.tsx @@ -1,8 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import React, { useRef } from 'react'; - -import { useCurrentMode } from '@cloudscape-design/component-toolkit/internal'; +import React from 'react'; import { Button as CloudscapeButton, SpaceBetween } from '~components'; @@ -52,11 +50,6 @@ interface CustomButtonProps { } function CustomButton({ children, colorTheme, id, isDisabled, isLoading, onClick, variation }: CustomButtonProps) { - const mode = useCurrentMode(useRef(document.body)); - const background = backgrounds[mode][colorTheme]; - const color = isDisabled || isLoading ? colors[mode] : colors[mode]; - const focusRing = focusRings[mode]; - return ( @@ -82,162 +75,90 @@ function CustomButton({ children, colorTheme, id, isDisabled, isLoading, onClick ); } -const backgrounds = { - light: { - default: { - active: palette.teal100, - default: palette.teal80, - disabled: palette.neutral40, - hover: palette.teal90, - }, - error: { - active: palette.red100, - default: palette.red80, - disabled: palette.neutral40, - hover: palette.red90, - }, - info: { - active: palette.blue100, - default: palette.blue80, - disabled: palette.neutral40, - hover: palette.blue90, - }, - success: { - active: palette.green100, - default: palette.green80, - disabled: palette.neutral40, - hover: palette.green90, - }, - warning: { - active: palette.orange100, - default: palette.orange80, - disabled: palette.neutral40, - hover: palette.orange90, - }, - }, - dark: { +function getBackground(colorTheme: string) { + const backgrounds = { default: { - active: palette.teal10, - default: palette.teal30, - disabled: palette.neutral80, - hover: palette.teal20, + active: `light-dark(${palette.teal100}, ${palette.teal10})`, + default: `light-dark(${palette.teal80}, ${palette.teal30})`, + disabled: `light-dark(${palette.neutral40}, ${palette.neutral80})`, + hover: `light-dark(${palette.teal90}, ${palette.teal20})`, }, error: { - active: palette.red10, - default: palette.red30, - disabled: palette.neutral80, - hover: palette.red20, + active: `light-dark(${palette.red100}, ${palette.red10})`, + default: `light-dark(${palette.red80}, ${palette.red30})`, + disabled: `light-dark(${palette.neutral40}, ${palette.neutral80})`, + hover: `light-dark(${palette.red90}, ${palette.red20})`, }, info: { - active: palette.blue10, - default: palette.blue40, - disabled: palette.neutral80, - hover: palette.blue20, + active: `light-dark(${palette.blue100}, ${palette.blue10})`, + default: `light-dark(${palette.blue80}, ${palette.blue40})`, + disabled: `light-dark(${palette.neutral40}, ${palette.neutral80})`, + hover: `light-dark(${palette.blue90}, ${palette.blue20})`, }, success: { - active: palette.green10, - default: palette.green30, - disabled: palette.neutral80, - hover: palette.green20, + active: `light-dark(${palette.green100}, ${palette.green10})`, + default: `light-dark(${palette.green80}, ${palette.green30})`, + disabled: `light-dark(${palette.neutral40}, ${palette.neutral80})`, + hover: `light-dark(${palette.green90}, ${palette.green20})`, }, warning: { - active: palette.orange10, - default: palette.orange40, - disabled: palette.neutral80, - hover: palette.orange20, + active: `light-dark(${palette.orange100}, ${palette.orange10})`, + default: `light-dark(${palette.orange80}, ${palette.orange40})`, + disabled: `light-dark(${palette.neutral40}, ${palette.neutral80})`, + hover: `light-dark(${palette.orange90}, ${palette.orange20})`, }, - }, -}; + }; + return backgrounds[colorTheme as keyof typeof backgrounds]; +} -const colors = { - light: { - active: palette.neutral10, - default: palette.neutral10, - hover: palette.neutral10, - disabled: palette.neutral60, - }, - dark: { - active: palette.neutral100, - default: palette.neutral100, - hover: palette.neutral100, - disabled: palette.neutral60, - }, -}; +function getColor() { + return { + active: `light-dark(${palette.neutral10}, ${palette.neutral100})`, + default: `light-dark(${palette.neutral10}, ${palette.neutral100})`, + hover: `light-dark(${palette.neutral10}, ${palette.neutral100})`, + disabled: `light-dark(${palette.neutral60}, ${palette.neutral60})`, + }; +} -const focusRings = { - light: { - borderColor: 'rgb(0, 64, 77)', +function getFocusRing() { + return { + borderColor: 'light-dark(rgb(0, 64, 77), rgb(233, 249, 252))', borderWidth: '2px', - }, - dark: { - borderColor: 'rgb(233, 249, 252)', - borderWidth: '2px', - }, -}; + }; +} -const boxShadows = { - light: { +function getBoxShadow(colorTheme: string) { + const boxShadows = { default: { - active: '0 4px 8px rgba(0, 128, 128, 0.3)', - default: '0 2px 4px rgba(0, 128, 128, 0.2)', + active: `0 4px 8px light-dark(rgba(0, 128, 128, 0.3), rgba(0, 255, 255, 0.4))`, + default: `0 2px 4px light-dark(rgba(0, 128, 128, 0.2), rgba(0, 255, 255, 0.3))`, disabled: 'none', - hover: '0 6px 12px rgba(0, 128, 128, 0.25)', + hover: `0 6px 12px light-dark(rgba(0, 128, 128, 0.25), rgba(0, 255, 255, 0.35))`, }, error: { - active: '0 4px 8px rgba(255, 0, 0, 0.3)', - default: '0 2px 4px rgba(255, 0, 0, 0.2)', + active: `0 4px 8px light-dark(rgba(255, 0, 0, 0.3), rgba(255, 100, 100, 0.4))`, + default: `0 2px 4px light-dark(rgba(255, 0, 0, 0.2), rgba(255, 100, 100, 0.3))`, disabled: 'none', - hover: '0 6px 12px rgba(255, 0, 0, 0.25)', + hover: `0 6px 12px light-dark(rgba(255, 0, 0, 0.25), rgba(255, 100, 100, 0.35))`, }, info: { - active: '0 4px 8px rgba(0, 0, 255, 0.3)', - default: '0 2px 4px rgba(0, 0, 255, 0.2)', + active: `0 4px 8px light-dark(rgba(0, 0, 255, 0.3), rgba(100, 100, 255, 0.4))`, + default: `0 2px 4px light-dark(rgba(0, 0, 255, 0.2), rgba(100, 100, 255, 0.3))`, disabled: 'none', - hover: '0 6px 12px rgba(0, 0, 255, 0.25)', + hover: `0 6px 12px light-dark(rgba(0, 0, 255, 0.25), rgba(100, 100, 255, 0.35))`, }, success: { - active: '0 4px 8px rgba(0, 255, 0, 0.3)', - default: '0 2px 4px rgba(0, 255, 0, 0.2)', + active: `0 4px 8px light-dark(rgba(0, 255, 0, 0.3), rgba(100, 255, 100, 0.4))`, + default: `0 2px 4px light-dark(rgba(0, 255, 0, 0.2), rgba(100, 255, 100, 0.3))`, disabled: 'none', - hover: '0 6px 12px rgba(0, 255, 0, 0.25)', + hover: `0 6px 12px light-dark(rgba(0, 255, 0, 0.25), rgba(100, 255, 100, 0.35))`, }, warning: { - active: '0 4px 8px rgba(255, 165, 0, 0.3)', - default: '0 2px 4px rgba(255, 165, 0, 0.2)', + active: `0 4px 8px light-dark(rgba(255, 165, 0, 0.3), rgba(255, 200, 100, 0.4))`, + default: `0 2px 4px light-dark(rgba(255, 165, 0, 0.2), rgba(255, 200, 100, 0.3))`, disabled: 'none', - hover: '0 6px 12px rgba(255, 165, 0, 0.25)', + hover: `0 6px 12px light-dark(rgba(255, 165, 0, 0.25), rgba(255, 200, 100, 0.35))`, }, - }, - dark: { - default: { - active: '0 4px 8px rgba(0, 255, 255, 0.4)', - default: '0 2px 4px rgba(0, 255, 255, 0.3)', - disabled: 'none', - hover: '0 6px 12px rgba(0, 255, 255, 0.35)', - }, - error: { - active: '0 4px 8px rgba(255, 100, 100, 0.4)', - default: '0 2px 4px rgba(255, 100, 100, 0.3)', - disabled: 'none', - hover: '0 6px 12px rgba(255, 100, 100, 0.35)', - }, - info: { - active: '0 4px 8px rgba(100, 100, 255, 0.4)', - default: '0 2px 4px rgba(100, 100, 255, 0.3)', - disabled: 'none', - hover: '0 6px 12px rgba(100, 100, 255, 0.35)', - }, - success: { - active: '0 4px 8px rgba(100, 255, 100, 0.4)', - default: '0 2px 4px rgba(100, 255, 100, 0.3)', - disabled: 'none', - hover: '0 6px 12px rgba(100, 255, 100, 0.35)', - }, - warning: { - active: '0 4px 8px rgba(255, 200, 100, 0.4)', - default: '0 2px 4px rgba(255, 200, 100, 0.3)', - disabled: 'none', - hover: '0 6px 12px rgba(255, 200, 100, 0.35)', - }, - }, -}; + }; + return boxShadows[colorTheme as keyof typeof boxShadows]; +} diff --git a/pages/button/style-permutations.page.tsx b/pages/button/style-permutations.page.tsx index 93a06b0946..05c0c5bf6b 100644 --- a/pages/button/style-permutations.page.tsx +++ b/pages/button/style-permutations.page.tsx @@ -2,99 +2,163 @@ // SPDX-License-Identifier: Apache-2.0 import React from 'react'; -import Button, { ButtonProps } from '~components/button'; +import { Button as CloudscapeButton, SpaceBetween } from '~components'; -import createPermutations from '../utils/permutations'; -import PermutationsView from '../utils/permutations-view'; +import { palette } from '../app/themes/style-api'; import ScreenshotArea from '../utils/screenshot-area'; -const permutations = createPermutations([ - { - ariaLabel: ['Border Styles'], - children: ['Border Styles'], - disabled: [false, true], - iconName: ['add-plus'], - iconAlt: ['add-plus'], - style: [ - { - root: { - borderColor: { - active: 'purple', - default: 'magenta', - hover: 'orange', - disabled: 'brown', - }, - borderRadius: '2px', - borderWidth: '4px', - }, - }, - ], - variant: ['primary', 'normal', 'link', 'icon', 'inline-icon', 'inline-link'], - }, - { - ariaLabel: ['Background and Color Styles'], - children: ['Background and Color Styles'], - disabled: [false, true], - iconName: ['arrow-left'], - iconAlt: ['arrow-left'], - loading: [false, true], - style: [ - { +export default function CustomButtonTypes() { + return ( + +

Custom Button Types

+ + + + Default + + + Success + + + Error + + + Info + + + Warning + + + isDisabled + + + isLoading + + +
+ ); +} + +interface CustomButtonProps { + children?: React.ReactNode; + colorTheme: 'default' | 'error' | 'info' | 'warning' | 'success'; + id?: string; + isDisabled?: boolean; + isLoading?: boolean; + onClick?: any; + variation: 'primary'; +} + +function CustomButton({ children, colorTheme, id, isDisabled, isLoading, onClick, variation }: CustomButtonProps) { + return ( + -

Button Style permutations

- -