Skip to content

fix(s2): update button gradients to use static colors #7574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions packages/@react-spectrum/s2/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,48 @@ const button = style<ButtonRenderProps & ButtonStyleProps & {isStaticColor: bool
backgroundImage: {
variant: {
premium: {
default: linearGradient('96deg', ['fuchsia-900', 0], ['indigo-900', 66], ['blue-900', 100]),
isHovered: linearGradient('96deg', ['fuchsia-1000', 0], ['indigo-1000', 66], ['blue-1000', 100]),
isPressed: linearGradient('96deg', ['fuchsia-1000', 0], ['indigo-1000', 66], ['blue-1000', 100]),
isFocusVisible: linearGradient('96deg', ['fuchsia-1000', 0], ['indigo-1000', 66], ['blue-1000', 100])
default: linearGradient('96deg',
['static-fuchsia-900', 'gradient-stop-1-premium'],
['static-indigo-900', 'gradient-stop-2-premium'],
['static-blue-900', 'gradient-stop-3-premium']
),
isHovered: linearGradient('96deg',
['static-fuchsia-1000', 'gradient-stop-1-premium'],
['static-indigo-1000', 'gradient-stop-2-premium'],
['static-blue-1000', 'gradient-stop-3-premium']
),
isPressed: linearGradient('96deg',
['static-fuchsia-1000', 'gradient-stop-1-premium'],
['static-indigo-1000', 'gradient-stop-2-premium'],
['static-blue-1000', 'gradient-stop-3-premium']
),
isFocusVisible: linearGradient('96deg',
['static-fuchsia-1000', 'gradient-stop-1-premium'],
['static-indigo-1000', 'gradient-stop-2-premium'],
['static-blue-1000', 'gradient-stop-3-premium']
)
},
genai: {
default: linearGradient('96deg', ['red-900', 0], ['magenta-900', 33], ['indigo-900', 100]),
isHovered: linearGradient('96deg', ['red-1000', 0], ['magenta-1000', 33], ['indigo-1000', 100]),
isPressed: linearGradient('96deg', ['red-1000', 0], ['magenta-1000', 33], ['indigo-1000', 100]),
isFocusVisible: linearGradient('96deg', ['red-1000', 0], ['magenta-1000', 33], ['indigo-1000', 100])
default: linearGradient('96deg',
['static-red-900', 'gradient-stop-1-genai'],
['static-magenta-900', 'gradient-stop-2-genai'],
['static-indigo-900', 'gradient-stop-3-genai']
),
isHovered: linearGradient('96deg',
['static-red-1000', 'gradient-stop-1-genai'],
['static-magenta-1000', 'gradient-stop-2-genai'],
['static-indigo-1000', 'gradient-stop-3-genai']
),
isPressed: linearGradient('96deg',
['static-red-1000', 'gradient-stop-1-genai'],
['static-magenta-1000', 'gradient-stop-2-genai'],
['static-indigo-1000', 'gradient-stop-3-genai']
),
isFocusVisible: linearGradient('96deg',
['static-red-1000', 'gradient-stop-1-genai'],
['static-magenta-1000', 'gradient-stop-2-genai'],
['static-indigo-1000', 'gradient-stop-3-genai']
)
}
},
isDisabled: 'none',
Expand Down
6 changes: 4 additions & 2 deletions packages/@react-spectrum/s2/style/spectrum-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {ArbitraryValue, CSSValue, PropertyValueMap} from './types';
import {autoStaticColor, colorScale, colorToken, fontSizeToken, generateOverlayColorScale, getToken, simpleColorScale, weirdColorToken} from './tokens' with {type: 'macro'};
import {Color, createArbitraryProperty, createColorProperty, createMappedProperty, createRenamedProperty, createSizingProperty, createTheme, parseArbitraryValue} from './style-macro';
import type * as CSS from 'csstype';
// eslint-disable-next-line rulesdir/imports
import * as tokens from '@adobe/spectrum-tokens/dist/json/variables.json';

interface MacroContext {
addAsset(asset: {type: string, content: string}): void
Expand Down Expand Up @@ -111,8 +113,8 @@ export function colorMix(a: SpectrumColor, b: SpectrumColor, percent: number): `
return `[color-mix(in srgb, ${parseColor(a)}, ${parseColor(b)} ${percent}%)]`;
}

export function linearGradient(angle: string, ...tokens: [SpectrumColor, number][]): string {
return `linear-gradient(${angle}, ${tokens.map(([color, stop]) => `${parseColor(color)} ${stop}%`)})`;
export function linearGradient(angle: string, ...gradientTokens: [(keyof typeof tokens), (keyof typeof tokens)][]): string {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure if making this function accept only tokens is ok. currently only used by the gradient buttons, but in the case someone else wanted to use it, it might need to accept color token as well?

return `linear-gradient(${angle}, ${gradientTokens.map(([color, stop]) => `${getToken(color)} ${parseFloat(getToken(stop)) * 100}%`)})`;
}

function generateSpacing<K extends number[]>(px: K): {[P in K[number]]: string} {
Expand Down
Loading