mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 21:32:40 +00:00
Add margin and padding functions
This commit is contained in:
parent
53558bc603
commit
a5b12d535f
2 changed files with 68 additions and 0 deletions
34
styles/src/component/margin.ts
Normal file
34
styles/src/component/margin.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
type MarginOptions = {
|
||||||
|
all?: number
|
||||||
|
left?: number
|
||||||
|
right?: number
|
||||||
|
top?: number
|
||||||
|
bottom?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type MarginStyle = {
|
||||||
|
top: number
|
||||||
|
bottom: number
|
||||||
|
left: number
|
||||||
|
right: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const margin_style = (options: MarginOptions): MarginStyle => {
|
||||||
|
const { all, top, bottom, left, right } = options
|
||||||
|
|
||||||
|
if (all !== undefined) return {
|
||||||
|
top: all,
|
||||||
|
bottom: all,
|
||||||
|
left: all,
|
||||||
|
right: all
|
||||||
|
}
|
||||||
|
|
||||||
|
if (top === undefined && bottom === undefined && left === undefined && right === undefined) throw new Error("Margin must have at least one value")
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: top || 0,
|
||||||
|
bottom: bottom || 0,
|
||||||
|
left: left || 0,
|
||||||
|
right: right || 0
|
||||||
|
}
|
||||||
|
}
|
34
styles/src/component/padding.ts
Normal file
34
styles/src/component/padding.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
type PaddingOptions = {
|
||||||
|
all?: number
|
||||||
|
left?: number
|
||||||
|
right?: number
|
||||||
|
top?: number
|
||||||
|
bottom?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PaddingStyle = {
|
||||||
|
top: number
|
||||||
|
bottom: number
|
||||||
|
left: number
|
||||||
|
right: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const padding_style = (options: PaddingOptions): PaddingStyle => {
|
||||||
|
const { all, top, bottom, left, right } = options
|
||||||
|
|
||||||
|
if (all !== undefined) return {
|
||||||
|
top: all,
|
||||||
|
bottom: all,
|
||||||
|
left: all,
|
||||||
|
right: all
|
||||||
|
}
|
||||||
|
|
||||||
|
if (top === undefined && bottom === undefined && left === undefined && right === undefined) throw new Error("Padding must have at least one value")
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: top || 0,
|
||||||
|
bottom: bottom || 0,
|
||||||
|
left: left || 0,
|
||||||
|
right: right || 0
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue