-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathflex-helpers.ts
121 lines (109 loc) · 3.34 KB
/
flex-helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// SPDX-FileCopyrightText: 2017-2022 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later
import { Property } from 'csstype'
import styled from 'styled-components'
import { defaultMargins, isSpacingSize, SpacingSize } from '../white-space'
interface FixedSpaceRowProps {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
spacing?: SpacingSize | string
justifyContent?: Property.JustifyContent
alignItems?: Property.AlignItems
fullWidth?: boolean
maxWidth?: string
flexWrap?: Property.FlexWrap
gap?: string
}
export const FixedSpaceRow = styled.div<FixedSpaceRowProps>`
display: flex;
flex-direction: row;
${(p) => (p.justifyContent ? `justify-content: ${p.justifyContent};` : '')}
${(p) => (p.alignItems ? `align-items: ${p.alignItems};` : '')}
${(p) => (p.fullWidth ? `width: 100%;` : '')}
${(p) => (p.flexWrap ? `flex-wrap: ${p.flexWrap};` : '')}
${(p) => (p.gap ? `gap: ${p.gap};` : '')}
>* {
margin-right: ${(p) =>
p.spacing
? isSpacingSize(p.spacing)
? defaultMargins[p.spacing]
: p.spacing
: defaultMargins.s};
&:last-child {
margin-right: 0;
}
${(p) => (p.maxWidth ? `max-width: ${p.maxWidth};` : '')};
}
> button {
margin-right: ${(p) =>
p.spacing
? isSpacingSize(p.spacing)
? defaultMargins[p.spacing]
: p.spacing
: defaultMargins.s};
&:last-child {
margin-right: 0;
}
}
`
interface FixedSpaceColumnProps {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
spacing?: SpacingSize | string
justifyContent?: Property.JustifyContent
alignItems?: Property.AlignItems
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
marginRight?: SpacingSize | string
fullWidth?: boolean
}
export const FixedSpaceColumn = styled.div<FixedSpaceColumnProps>`
display: flex;
flex-direction: column;
${(p) => (p.justifyContent ? `justify-content: ${p.justifyContent};` : '')}
${(p) => (p.alignItems ? `align-items: ${p.alignItems};` : '')}
${(p) => (p.fullWidth ? `width: 100%;` : '')}
${(p) =>
p.marginRight
? `margin-right: ${
isSpacingSize(p.marginRight)
? defaultMargins[p.marginRight]
: p.marginRight
};`
: ''}
>* {
margin-bottom: ${(p) =>
p.spacing
? isSpacingSize(p.spacing)
? defaultMargins[p.spacing]
: p.spacing
: defaultMargins.s};
&:last-child {
margin-bottom: 0;
}
}
`
interface FixedSpaceFlexWrapProps {
horizontalSpacing?: SpacingSize
verticalSpacing?: SpacingSize
reverse?: boolean
}
export const FixedSpaceFlexWrap = styled.div<FixedSpaceFlexWrapProps>`
display: flex;
flex-direction: row;
flex-wrap: ${(p) => (p.reverse ? 'wrap-reverse' : 'wrap')};
justify-content: flex-start;
align-items: flex-start;
margin-bottom: -${(p) =>
p.verticalSpacing ? defaultMargins[p.verticalSpacing] : defaultMargins.s};
margin-right: -${(p) =>
p.horizontalSpacing
? defaultMargins[p.horizontalSpacing]
: defaultMargins.s};
> * {
margin-bottom: ${(p) =>
p.verticalSpacing ? defaultMargins[p.verticalSpacing] : defaultMargins.s};
margin-right: ${(p) =>
p.horizontalSpacing
? defaultMargins[p.horizontalSpacing]
: defaultMargins.s};
}
`