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(theme): Add accessible-ink-color function #1719

Merged
merged 4 commits into from
Dec 8, 2017
Merged
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
13 changes: 13 additions & 0 deletions packages/mdc-theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,16 @@ It only returns the raw color value of the specified theme property.
@debug mdc-theme-prop-value(primary); // #3f51b5
@debug mdc-theme-prop-value(blue); // blue
```

#### `mdc-theme-accessible-ink-color($fill-color)`
Copy link
Contributor

Choose a reason for hiding this comment

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

mdc-theme-accessible-primary-ink-color? Since it always returns primary text colors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! I made it a parameter called $text-style, which defaults to primary.


Returns an accessible ink color that has sufficient contrast against the given fill color.

Supports the same values as `mdc-theme-prop-value`.

> NOTE: This function is defined in `_variables.scss` instead of `_functions.scss` to avoid circular imports.

```scss
@debug mdc-theme-accessible-ink-color(secondary); // rgba(0, 0, 0, .87) (text-primary-on-light)
@debug mdc-theme-accessible-ink-color(blue); // white (text-primary-on-dark)
```
7 changes: 7 additions & 0 deletions packages/mdc-theme/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,10 @@ $mdc-theme-property-values: (

@return map-get($mdc-theme-property-values, $property);
}

// NOTE: This function must be defined in _variables.scss instead of _functions.scss to avoid circular imports.
@function mdc-theme-accessible-ink-color($fill-color) {
$fill-color-value: mdc-theme-prop-value($fill-color);

@return map-get(map-get($mdc-theme-text-colors, mdc-theme-contrast-tone($fill-color-value)), primary);
}