-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@griffel-core-e9730721-98ad-4971-8976-6f934c35cf1f.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Adds inset shorthand", | ||
"packageName": "@griffel/core", | ||
"email": "bsunderhus@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { inset } from './inset'; | ||
|
||
describe('inset', () => { | ||
it('for a given value', () => { | ||
expect(inset('12px')).toEqual({ | ||
bottom: '12px', | ||
left: '12px', | ||
right: '12px', | ||
top: '12px', | ||
}); | ||
}); | ||
|
||
it('for given vertical and horizontal values', () => { | ||
expect(inset('12px', '24px')).toEqual({ | ||
bottom: '12px', | ||
left: '24px', | ||
right: '24px', | ||
top: '12px', | ||
}); | ||
}); | ||
|
||
it('for given top, horizontal and bottom values', () => { | ||
expect(inset('12px', '24px', '36px')).toEqual({ | ||
bottom: '36px', | ||
left: '24px', | ||
right: '24px', | ||
top: '12px', | ||
}); | ||
}); | ||
|
||
it('for given top, right, bottom and left values', () => { | ||
expect(inset('12px', '24px', '36px', '48px')).toEqual({ | ||
bottom: '36px', | ||
left: '48px', | ||
right: '24px', | ||
top: '12px', | ||
}); | ||
}); | ||
|
||
it('for a given zero value', () => { | ||
expect(inset(0)).toEqual({ | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
}); | ||
}); | ||
|
||
it('for fallback value arrays', () => { | ||
expect(inset([0, '12px'], ['auto', '-2px'])).toEqual({ | ||
bottom: [0, '12px'], | ||
left: ['auto', '-2px'], | ||
right: ['auto', '-2px'], | ||
top: [0, '12px'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { GriffelStylesStrictCSSObject } from '../types'; | ||
import { InsetInput } from './types'; | ||
|
||
type InsetStyle = Pick<GriffelStylesStrictCSSObject, 'top' | 'right' | 'bottom' | 'left'>; | ||
|
||
export function inset(all: InsetInput): InsetStyle; | ||
export function inset(vertical: InsetInput, horizontal: InsetInput): InsetStyle; | ||
export function inset(top: InsetInput, horizontal: InsetInput, bottom: InsetInput): InsetStyle; | ||
export function inset(top: InsetInput, right: InsetInput, bottom: InsetInput, left: InsetInput): InsetStyle; | ||
|
||
/** | ||
* A function that implements CSS spec conformant expansion for "inset" | ||
* | ||
* @example | ||
* inset('10px') | ||
* inset('10px', '5px') | ||
* inset('2px', '4px', '8px') | ||
* inset('1px', 0, '3px', '4px') | ||
* | ||
* See https://developer.mozilla.org/en-US/docs/Web/CSS/inset | ||
*/ | ||
export function inset(...values: InsetInput[]): InsetStyle { | ||
const [firstValue, secondValue = firstValue, thirdValue = firstValue, fourthValue = secondValue] = values; | ||
return { | ||
top: firstValue, | ||
right: secondValue, | ||
bottom: thirdValue, | ||
left: fourthValue, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters