66 modularScale ,
77 darken ,
88 parseToRgb ,
9+ mix ,
910} from 'polished'
1011import { th , mixin } from '../utils'
1112
@@ -151,6 +152,16 @@ export const controlFocusBorderColor = th('primary', color =>
151152export const controlFocusBoxShadow = color =>
152153 css `0 0 0 0.2rem ${ th ( color , c => transparentize ( 0.75 , c ) ) } `
153154
155+ // Alerts
156+
157+ export const alertPaddingY = '.75rem'
158+ export const alertPaddingX = '1.25rem'
159+ export const alertMarginBottom = '1rem'
160+
161+ export const alertBgLevel = - 10
162+ export const alertBorderLevel = - 9
163+ export const alertColorLevel = 6
164+
154165// Z-indexes
155166
156167export const zIndexControl = 1
@@ -170,15 +181,20 @@ export const breakPoints = {
170181 xl : 1200 ,
171182}
172183
184+ // Color levels
185+
186+ export const yiqContrastedThreshold = 150
187+ export const colorInterval = 0.08
188+
173189// Mixins
174190
175- export const controlFocus = ( baseColor = 'primary' ) => css `
191+ export const controlFocus = props => ( baseColor = 'primary' ) => css `
176192 outline: 0;
177193 box- shadow: 0 0 2px ${ th ( baseColor , color => transparentize ( 0.1 , color ) ) } ;
178194`
179195
180- export const btnVariant = baseColor => css `
181- color : ${ props => props . theme . colorYik ( th ( baseColor ) ( props ) ) } ;
196+ export const btnVariant = props => baseColor => css `
197+ color : ${ mixin ( 'colorYik' , th ( baseColor ) ) } ;
182198 background- color : ${ th ( baseColor ) } ;
183199
184200 & : focus {
@@ -191,8 +207,34 @@ export const btnVariant = baseColor => css`
191207 }
192208`
193209
194- export const colorYik = color => {
210+ export const alertVariant = props => baseColor =>
211+ css `
212+ color : ${ mixin ( 'colorLevel' , th ( baseColor ) , th ( 'alertColorLevel' ) ) } ;
213+ background-color : ${ mixin ( 'colorLevel' , th ( baseColor ) , th ( 'alertBgLevel' ) ) } ;
214+ border-color : ${ mixin ( 'colorLevel' , th ( baseColor ) , th ( 'alertBorderLevel' ) ) } ;
215+
216+ hr {
217+ border-top-color : ${ props =>
218+ darken (
219+ 0.05 ,
220+ mixin ( 'colorLevel' , th ( baseColor ) , th ( 'alertColorLevel' ) ) ( props ) ,
221+ ) } ;
222+ }
223+ `
224+
225+ export const colorLevel = props => ( color , level ) => {
226+ color = typeof color === 'function' ? color ( props ) : color
227+ level = typeof level === 'function' ? level ( props ) : level
228+ const baseColor = level > 0 ? th ( 'black' ) ( props ) : th ( 'white' ) ( props )
229+ const absLevel = Math . abs ( level )
230+ return mix ( absLevel * colorInterval , baseColor , color )
231+ }
232+
233+ export const colorYik = props => color => {
234+ color = typeof color === 'function' ? color ( props ) : color
195235 const { red : r , green : g , blue : b } = parseToRgb ( color )
196236 const yik = ( r * 299 + g * 587 + b * 114 ) / 1000
197- return yik >= 150 ? th ( 'yikTextDark' ) : th ( 'yikTextLight' )
237+ return yik >= th ( 'yiqContrastedThreshold' ) ( props )
238+ ? th ( 'yikTextDark' ) ( props )
239+ : th ( 'yikTextLight' ) ( props )
198240}
0 commit comments