Skip to content
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

feat(gradient): linear gradient mixin #15081

Merged
merged 9 commits into from
Nov 7, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

exports[`Public API should only change with a semver change 1`] = `
Array [
"aiGradientEnd",
"aiGradientStart01",
"aiGradientStart02",
"background",
"backgroundActive",
"backgroundBrand",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright IBM Corp. 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import { Tile } from '../Tile';
import { TextInput } from '../TextInput';
import './linear-gradient-story.scss';

export default {
title: 'Experimental/unstable__LinearGradient',
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about having this in the storybook long term. Feels more like something we should find a way to document in the Themes elements example. Not a blocker for this PR, but something to consider for the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I can remove this before we merge 👍🏻

component: Tile,
};

export const Demo = () => (
<>
<div className="gradient-container">
<Tile className="top">Top</Tile>
<Tile className="right">Right</Tile>
<Tile className="bottom">Bottom</Tile>
<Tile className="left">Left</Tile>
</div>
<br />
<br />
<div className="gradient-container">
<TextInput labelText="Full width" className="full-width" />
<TextInput labelText="Half width" className="half-width" />
<TextInput labelText="Third width" className="third-width" />
<TextInput labelText="Quarter width" className="quarter-width" />
</div>
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@use '../../../../styles/scss/utilities/ai-gradient' as *;

.gradient-container {
display: flex;
flex-direction: row;
justify-content: space-between;
}

.gradient-container > * {
margin: 0 0.5rem;
}

.gradient-container > .cds--tile {
min-height: 250px;
min-width: 150px;
}

.top {
@include ai-gradient('top');
}

.right {
@include ai-gradient('right');
}

.bottom {
@include ai-gradient('bottom');
}

.left {
@include ai-gradient('left');
}

.full-width .cds--text-input {
@include ai-gradient('right', 100%);
}

.half-width .cds--text-input {
@include ai-gradient('right', 50%);
}

.third-width .cds--text-input {
@include ai-gradient('right', 33%);
}

.quarter-width .cds--text-input {
@include ai-gradient('right', 25%);
}
3 changes: 3 additions & 0 deletions packages/styles/scss/__tests__/theme-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ describe('@carbon/styles/scss/theme', () => {
"slug-callout-gradient-bottom",
"slug-callout-aura-start",
"slug-callout-aura-end",
"ai-gradient-start-01",
"ai-gradient-start-02",
"ai-gradient-end",
"highlight",
"overlay",
"toggle-off",
Expand Down
41 changes: 41 additions & 0 deletions packages/styles/scss/utilities/_ai-gradient.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright IBM Corp. 2021
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '../theme';

/// Adds AI gradient styles to a component
/// @access public
Copy link
Member

Choose a reason for hiding this comment

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

Should @access private be used for experimental? If it's public, then it's part of our public API as supported.

http://sassdoc.com/annotations/#access

/// @param {String} $direction - Direction of gradient from: `left`, `right`, `top`, and `bottom`
/// @param {Number} $width - Percentage width of gradient with regards to parent component
/// @example @include focus-outline('outline');
/// @group utilities

@mixin ai-gradient($direction: 'right', $width: 50%) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm also questioning our use of ai- in token and mixin naming. Following the token naming convention shown here, would we want to go with gradient-01?

This could be more future proof. What happens when everything is "AI". We don't want our code base littered with ai prefixes/namespaces. A few years from now, that will seem silly.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah @tay1orjones has mentioned the same thing about the "ai" term. We haven't finalized the token name yet just launching something so TJ isn't blocked for the next implementation steps. I think we were going to try and avoid "gradient" as well since that's not scalable (could evolve to something other than a linear gradient). I was thinking it could just be a flavor of "aura" (like aura-static) or whatever we end up calling that in the AI world.

$deg: 0;
@if $direction == 'bottom' {
$deg: 0deg;
} @else if $direction == 'left' {
$deg: 90deg;
} @else if $direction == 'top' {
$deg: 180deg;
} @else if $direction == 'right' {
$deg: 270deg;
}

background-image: linear-gradient(
$deg,
theme.$ai-gradient-start-01 0%,
theme.$ai-gradient-end $width,
transparent 100%
),
linear-gradient(
$deg,
theme.$ai-gradient-start-02 0%,
theme.$ai-gradient-end $width,
transparent 100%
);
}
1 change: 1 addition & 0 deletions packages/styles/scss/utilities/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// LICENSE file in the root directory of this source tree.
//

@forward 'ai-gradient';
@forward 'box-shadow';
@forward 'button-reset' as button-*;
@forward 'component-reset' as component-*;
Expand Down
10 changes: 9 additions & 1 deletion packages/themes/src/g10.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
blue60,
blue70,

// CoolGray
coolGray10,

// Gray
gray10,
gray10Hover,
Expand Down Expand Up @@ -202,7 +205,8 @@ export const overlay = 'rgba(22, 22, 22, 0.5)';
export const toggleOff = gray50;
export const shadow = 'rgba(0, 0, 0, 0.3)';

// AI
//// AI
// Slug tokens
export const slugBackground = gray70;
export const slugGradient = `${gray100} linear-gradient(135deg, ${gray40} 0%, rgba(${white}, 0) 100%)`;
export const slugBackgroundHover = gray60;
Expand All @@ -212,6 +216,10 @@ export const slugCalloutGradientTop = rgba(gray10, 0.85);
export const slugCalloutGradientBottom = rgba(gray20, 0.85);
export const slugCalloutAuraStart = rgba(blue10, 0.6);
export const slugCalloutAuraEnd = rgba(white, 0);
// Linear gradient tokens
export const aiGradientStart01 = rgba(coolGray10, 0.5);
export const aiGradientStart02 = rgba(blue10, 0.5);
export const aiGradientEnd = rgba(white, 0);

export {
// Type
Expand Down
7 changes: 6 additions & 1 deletion packages/themes/src/g100.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export const overlay = rgba(black, 0.65);
export const toggleOff = gray60;
export const shadow = rgba(black, 0.8);

// AI
//// AI
// Slug tokens
export const slugBackground = gray30;
export const slugGradient = `${gray50} linear-gradient(135deg, ${gray10} 0%, rgba(${white}, 0) 100%)`;
export const slugBackgroundHover = gray20;
Expand All @@ -220,6 +221,10 @@ export const slugCalloutGradientTop = rgba(gray100, 0.85);
export const slugCalloutGradientBottom = rgba(gray90, 0.85);
export const slugCalloutAuraStart = rgba(blue20, 0.2);
export const slugCalloutAuraEnd = rgba(gray100, 0);
// Linear gradient tokens
export const aiGradientStart01 = rgba(blue20, 0.2);
export const aiGradientStart02 = 'transparent';
export const aiGradientEnd = 'rgba(38, 38, 38, 0)';

export {
// Type
Expand Down
7 changes: 6 additions & 1 deletion packages/themes/src/g90.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export const overlay = rgba(black, 0.65);
export const toggleOff = gray50;
export const shadow = rgba(black, 0.8);

// AI
//// AI
// Slug tokens
export const slugBackground = gray30;
export const slugGradient = `${gray50} linear-gradient(135deg, ${gray10} 0%, rgba(${white}, 0) 100%)`;
export const slugBackgroundHover = gray20;
Expand All @@ -220,6 +221,10 @@ export const slugCalloutGradientTop = rgba(gray100, 0.85);
export const slugCalloutGradientBottom = rgba(gray90, 0.85);
export const slugCalloutAuraStart = rgba(blue20, 0.2);
export const slugCalloutAuraEnd = rgba(gray100, 0);
// Linear gradient tokens
export const aiGradientStart01 = rgba(blue20, 0.2);
export const aiGradientStart02 = 'transparent';
export const aiGradientEnd = 'rgba(38, 38, 38, 0)';

export {
// Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ Array [
"slug-callout-gradient-bottom",
"slug-callout-aura-start",
"slug-callout-aura-end",
"ai-gradient-start-01",
"ai-gradient-start-02",
"ai-gradient-end",
"highlight",
"overlay",
"toggle-off",
Expand Down
12 changes: 12 additions & 0 deletions packages/themes/src/tokens/__tests__/metadata-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,18 @@ test('metadata', () => {
"name": "slug-callout-aura-end",
"type": "color",
},
Object {
"name": "ai-gradient-start-01",
"type": "color",
},
Object {
"name": "ai-gradient-start-02",
"type": "color",
},
Object {
"name": "ai-gradient-end",
"type": "color",
},
Object {
"name": "highlight",
"type": "color",
Expand Down
3 changes: 3 additions & 0 deletions packages/themes/src/tokens/v11TokenGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ export const ai = TokenGroup.create({
'slug-callout-gradient-bottom',
'slug-callout-aura-start',
'slug-callout-aura-end',
'ai-gradient-start-01',
'ai-gradient-start-02',
'ai-gradient-end',
],
});

Expand Down
10 changes: 9 additions & 1 deletion packages/themes/src/white.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
blue60,
blue70,

// CoolGray
coolGray10,

// Gray
gray10,
gray10Hover,
Expand Down Expand Up @@ -202,7 +205,8 @@ export const overlay = 'rgba(22, 22, 22, 0.5)';
export const toggleOff = gray50;
export const shadow = 'rgba(0, 0, 0, 0.3)';

// AI
//// AI
// Slug tokens
export const slugBackground = gray70;
export const slugGradient = `${gray100} linear-gradient(135deg, ${gray40} 0%, rgba(${white}, 0) 100%)`;
export const slugBackgroundHover = gray60;
Expand All @@ -212,6 +216,10 @@ export const slugCalloutGradientTop = rgba(gray10, 0.85);
export const slugCalloutGradientBottom = rgba(gray20, 0.85);
export const slugCalloutAuraStart = rgba(blue10, 0.6);
export const slugCalloutAuraEnd = rgba(white, 0);
// Linear gradient tokens
export const aiGradientStart01 = rgba(coolGray10, 0.5);
export const aiGradientStart02 = rgba(blue10, 0.5);
export const aiGradientEnd = rgba(white, 0);

// Type
export {
Expand Down