@instructure/ui-flex 11.6.0 → 11.6.1-snapshot-129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -281
- package/es/Flex/{Item → v1/Item}/index.js +2 -2
- package/es/Flex/{index.js → v1/index.js} +2 -2
- package/es/Flex/v2/Item/index.js +97 -0
- package/es/Flex/v2/Item/props.js +26 -0
- package/es/Flex/v2/Item/styles.js +68 -0
- package/es/Flex/v2/index.js +119 -0
- package/es/Flex/v2/props.js +26 -0
- package/es/Flex/v2/styles.js +101 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -5
- package/lib/Flex/{Item → v1/Item}/index.js +3 -3
- package/lib/Flex/v1/index.js +135 -0
- package/lib/Flex/v2/Item/index.js +102 -0
- package/lib/Flex/v2/Item/props.js +31 -0
- package/lib/Flex/v2/Item/styles.js +74 -0
- package/lib/Flex/{index.js → v2/index.js} +3 -4
- package/lib/Flex/v2/props.js +31 -0
- package/lib/Flex/v2/styles.js +107 -0
- package/lib/{index.js → exports/a.js} +3 -3
- package/lib/exports/b.js +18 -0
- package/package.json +38 -16
- package/src/Flex/{Item → v1/Item}/index.tsx +2 -2
- package/src/Flex/{index.tsx → v1/index.tsx} +2 -2
- package/src/Flex/v2/Item/index.tsx +115 -0
- package/src/Flex/v2/Item/props.ts +146 -0
- package/src/Flex/v2/Item/styles.ts +66 -0
- package/src/Flex/v2/README.md +419 -0
- package/src/Flex/v2/index.tsx +157 -0
- package/src/Flex/v2/props.ts +152 -0
- package/src/Flex/v2/styles.ts +112 -0
- package/src/exports/a.ts +28 -0
- package/src/exports/b.ts +28 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Flex/v1/Item/index.d.ts.map +1 -0
- package/types/Flex/v1/Item/props.d.ts.map +1 -0
- package/types/Flex/v1/Item/styles.d.ts.map +1 -0
- package/types/Flex/v1/index.d.ts.map +1 -0
- package/types/Flex/v1/props.d.ts.map +1 -0
- package/types/Flex/v1/styles.d.ts.map +1 -0
- package/types/Flex/v1/theme.d.ts.map +1 -0
- package/types/Flex/v2/Item/index.d.ts +41 -0
- package/types/Flex/v2/Item/index.d.ts.map +1 -0
- package/types/Flex/v2/Item/props.d.ts +79 -0
- package/types/Flex/v2/Item/props.d.ts.map +1 -0
- package/types/Flex/v2/Item/styles.d.ts +14 -0
- package/types/Flex/v2/Item/styles.d.ts.map +1 -0
- package/types/Flex/v2/index.d.ts +49 -0
- package/types/Flex/v2/index.d.ts.map +1 -0
- package/types/Flex/v2/props.d.ts +83 -0
- package/types/Flex/v2/props.d.ts.map +1 -0
- package/types/Flex/v2/styles.d.ts +19 -0
- package/types/Flex/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +4 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +4 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Flex/Item/index.d.ts.map +0 -1
- package/types/Flex/Item/props.d.ts.map +0 -1
- package/types/Flex/Item/styles.d.ts.map +0 -1
- package/types/Flex/index.d.ts.map +0 -1
- package/types/Flex/props.d.ts.map +0 -1
- package/types/Flex/styles.d.ts.map +0 -1
- package/types/Flex/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -4
- package/types/index.d.ts.map +0 -1
- /package/es/Flex/{Item → v1/Item}/props.js +0 -0
- /package/es/Flex/{Item → v1/Item}/styles.js +0 -0
- /package/es/Flex/{props.js → v1/props.js} +0 -0
- /package/es/Flex/{styles.js → v1/styles.js} +0 -0
- /package/es/Flex/{theme.js → v1/theme.js} +0 -0
- /package/lib/Flex/{Item → v1/Item}/props.js +0 -0
- /package/lib/Flex/{Item → v1/Item}/styles.js +0 -0
- /package/lib/Flex/{props.js → v1/props.js} +0 -0
- /package/lib/Flex/{styles.js → v1/styles.js} +0 -0
- /package/lib/Flex/{theme.js → v1/theme.js} +0 -0
- /package/src/Flex/{Item → v1/Item}/props.ts +0 -0
- /package/src/Flex/{Item → v1/Item}/styles.ts +0 -0
- /package/src/Flex/{README.md → v1/README.md} +0 -0
- /package/src/Flex/{props.ts → v1/props.ts} +0 -0
- /package/src/Flex/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Flex/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Flex/{Item → v1/Item}/index.d.ts +0 -0
- /package/types/Flex/{Item → v1/Item}/props.d.ts +0 -0
- /package/types/Flex/{Item → v1/Item}/styles.d.ts +0 -0
- /package/types/Flex/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/Flex/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Flex/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Flex/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { ComponentElement, Children, Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
safeCloneElement,
|
|
29
|
+
passthroughProps,
|
|
30
|
+
matchComponentTypes,
|
|
31
|
+
callRenderProp
|
|
32
|
+
} from '@instructure/ui-react-utils'
|
|
33
|
+
import { View } from '@instructure/ui-view/latest'
|
|
34
|
+
import { withStyle } from '@instructure/emotion'
|
|
35
|
+
|
|
36
|
+
import { Item } from './Item'
|
|
37
|
+
import type { FlexItemProps } from './Item/props'
|
|
38
|
+
|
|
39
|
+
import generateStyle from './styles'
|
|
40
|
+
|
|
41
|
+
import { allowedProps } from './props'
|
|
42
|
+
import type { FlexProps } from './props'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
---
|
|
46
|
+
category: components
|
|
47
|
+
---
|
|
48
|
+
@module Flex
|
|
49
|
+
**/
|
|
50
|
+
@withStyle(generateStyle)
|
|
51
|
+
class Flex extends Component<FlexProps> {
|
|
52
|
+
static readonly componentId = 'Flex'
|
|
53
|
+
|
|
54
|
+
componentDidMount() {
|
|
55
|
+
this.props.makeStyles?.()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
componentDidUpdate() {
|
|
59
|
+
this.props.makeStyles?.()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static Item = Item
|
|
63
|
+
|
|
64
|
+
static allowedProps = allowedProps
|
|
65
|
+
static defaultProps = {
|
|
66
|
+
as: 'span',
|
|
67
|
+
direction: 'row',
|
|
68
|
+
justifyItems: 'start',
|
|
69
|
+
display: 'flex',
|
|
70
|
+
withVisualDebug: false,
|
|
71
|
+
wrap: 'no-wrap',
|
|
72
|
+
gap: 'none'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
ref: Element | null = null
|
|
76
|
+
|
|
77
|
+
handleRef = (el: Element | null) => {
|
|
78
|
+
const { elementRef } = this.props
|
|
79
|
+
|
|
80
|
+
this.ref = el
|
|
81
|
+
|
|
82
|
+
if (typeof elementRef === 'function') {
|
|
83
|
+
elementRef(el)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
renderChildren(children: FlexProps['children']) {
|
|
88
|
+
// TODO this might fail if children are () => ReactNode
|
|
89
|
+
return Children.map(children as React.ReactNode, (child) => {
|
|
90
|
+
if (!child) {
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return matchComponentTypes<ComponentElement<FlexItemProps, Item>>(child, [
|
|
95
|
+
'Item'
|
|
96
|
+
])
|
|
97
|
+
? safeCloneElement(child, {
|
|
98
|
+
// child withVisualDebug prop should override parent
|
|
99
|
+
withVisualDebug: this.props.withVisualDebug,
|
|
100
|
+
...child.props,
|
|
101
|
+
direction: this.props.direction!.replace(
|
|
102
|
+
/-reverse/,
|
|
103
|
+
''
|
|
104
|
+
) as FlexItemProps['direction']
|
|
105
|
+
})
|
|
106
|
+
: child
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
render() {
|
|
111
|
+
const {
|
|
112
|
+
as,
|
|
113
|
+
withVisualDebug,
|
|
114
|
+
height,
|
|
115
|
+
display,
|
|
116
|
+
margin,
|
|
117
|
+
padding,
|
|
118
|
+
textAlign,
|
|
119
|
+
width,
|
|
120
|
+
styles,
|
|
121
|
+
gap,
|
|
122
|
+
wrap
|
|
123
|
+
} = this.props
|
|
124
|
+
|
|
125
|
+
const children = callRenderProp(this.props.children)
|
|
126
|
+
|
|
127
|
+
const gapValuesArray = gap?.split(' ')
|
|
128
|
+
if (gapValuesArray!.length > 1 && wrap === 'no-wrap')
|
|
129
|
+
console.warn(
|
|
130
|
+
'The `gap` prop is supplied with an improper `wrap=no-wrap` prop.'
|
|
131
|
+
)
|
|
132
|
+
if (children && Children.count(children) > 0) {
|
|
133
|
+
return (
|
|
134
|
+
<View
|
|
135
|
+
{...passthroughProps(this.props)}
|
|
136
|
+
css={styles?.flex}
|
|
137
|
+
elementRef={this.handleRef}
|
|
138
|
+
as={as}
|
|
139
|
+
display={display}
|
|
140
|
+
width={width}
|
|
141
|
+
height={height}
|
|
142
|
+
margin={margin}
|
|
143
|
+
padding={padding}
|
|
144
|
+
textAlign={textAlign}
|
|
145
|
+
withVisualDebug={withVisualDebug}
|
|
146
|
+
>
|
|
147
|
+
{this.renderChildren(children)}
|
|
148
|
+
</View>
|
|
149
|
+
)
|
|
150
|
+
} else {
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default Flex
|
|
157
|
+
export { Flex, Item as FlexItem }
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type {
|
|
26
|
+
AsElementType,
|
|
27
|
+
FlexTheme,
|
|
28
|
+
OtherHTMLAttributes,
|
|
29
|
+
Renderable
|
|
30
|
+
} from '@instructure/shared-types'
|
|
31
|
+
import type {
|
|
32
|
+
Spacing,
|
|
33
|
+
WithStyleProps,
|
|
34
|
+
ComponentStyle
|
|
35
|
+
} from '@instructure/emotion'
|
|
36
|
+
|
|
37
|
+
type FlexOwnProps = {
|
|
38
|
+
/**
|
|
39
|
+
* It's recommended that you use `Flex.Item` for children, but you can also
|
|
40
|
+
* pass any markup or a function returning markup.
|
|
41
|
+
*
|
|
42
|
+
* Note that if you do not use `Flex.Item`, the `withVisualDebug` and
|
|
43
|
+
* `direction` props will not automatically be set on the children.
|
|
44
|
+
*/
|
|
45
|
+
children?: Renderable
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* the element type to render as
|
|
49
|
+
*/
|
|
50
|
+
as?: AsElementType
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* provides a reference to the underlying html root element
|
|
54
|
+
*/
|
|
55
|
+
elementRef?: (element: Element | null) => void
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sets the height of the component's container (optional)
|
|
59
|
+
*/
|
|
60
|
+
height?: string | number
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sets the width of the component's container (optional)
|
|
64
|
+
*/
|
|
65
|
+
width?: string | number
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
69
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
70
|
+
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
71
|
+
*/
|
|
72
|
+
margin?: Spacing
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Valid values are `0`, `none`, `auto`, and Spacing token values,
|
|
76
|
+
* see https://instructure.design/layout-spacing. Apply these values via
|
|
77
|
+
* familiar CSS-like shorthand. For example, `gap="small auto large"`.
|
|
78
|
+
*/
|
|
79
|
+
gap?: Spacing
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Valid values are `0`, `none`, `xxx-small`, `xx-small`, `x-small`,
|
|
83
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
84
|
+
* familiar CSS-like shorthand. For example: `padding="small x-large large"`.
|
|
85
|
+
*/
|
|
86
|
+
padding?: Spacing
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Sets the CSS display rule for the component's container
|
|
90
|
+
*/
|
|
91
|
+
display?: 'flex' | 'inline-flex'
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Designates the text alignment
|
|
95
|
+
*/
|
|
96
|
+
textAlign?: 'start' | 'center' | 'end'
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Sets the flex-direction to row (horizontal) or column (vertical)
|
|
100
|
+
*/
|
|
101
|
+
direction?: 'row' | 'column' | 'row-reverse' | 'column-reverse'
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Aligns Flex.Items on the vertical axis (horizontal if direction is column)
|
|
105
|
+
*/
|
|
106
|
+
alignItems?: 'center' | 'start' | 'end' | 'stretch'
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Aligns Flex.Items on the horizontal axis (vertical if direction is column)
|
|
110
|
+
*/
|
|
111
|
+
justifyItems?: 'center' | 'start' | 'end' | 'space-around' | 'space-between'
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Determines if the Flex.Items should wrap when they exceed their container's width
|
|
115
|
+
*/
|
|
116
|
+
wrap?: 'wrap' | 'no-wrap' | 'wrap-reverse'
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Activate a dotted outline around the component to make building your
|
|
120
|
+
* layout easier
|
|
121
|
+
*/
|
|
122
|
+
withVisualDebug?: boolean
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
type PropKeys = keyof FlexOwnProps
|
|
126
|
+
|
|
127
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
128
|
+
|
|
129
|
+
type FlexProps = FlexOwnProps &
|
|
130
|
+
WithStyleProps<FlexTheme, FlexStyle> &
|
|
131
|
+
OtherHTMLAttributes<FlexOwnProps>
|
|
132
|
+
|
|
133
|
+
type FlexStyle = ComponentStyle<'flex'>
|
|
134
|
+
const allowedProps: AllowedPropKeys = [
|
|
135
|
+
'children',
|
|
136
|
+
'as',
|
|
137
|
+
'elementRef',
|
|
138
|
+
'height',
|
|
139
|
+
'width',
|
|
140
|
+
'margin',
|
|
141
|
+
'padding',
|
|
142
|
+
'display',
|
|
143
|
+
'textAlign',
|
|
144
|
+
'direction',
|
|
145
|
+
'alignItems',
|
|
146
|
+
'justifyItems',
|
|
147
|
+
'wrap',
|
|
148
|
+
'withVisualDebug'
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
export type { FlexProps, FlexStyle }
|
|
152
|
+
export { allowedProps }
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { getShorthandPropValue, makeThemeVars } from '@instructure/emotion'
|
|
26
|
+
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
|
|
27
|
+
import type { FlexProps, FlexStyle } from './props'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* ---
|
|
31
|
+
* private: true
|
|
32
|
+
* ---
|
|
33
|
+
* Generates the style object from the theme and provided additional information
|
|
34
|
+
* @param {Object} componentTheme The theme variable object.
|
|
35
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
36
|
+
* @param {string} props.justifyItems
|
|
37
|
+
* @param {string} props.direction
|
|
38
|
+
* @param {string} props.alignItems
|
|
39
|
+
* @param {string} props.wrap
|
|
40
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
41
|
+
* @return {Object} The final style object, which will be used in the component
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
const generateStyle = (
|
|
45
|
+
componentTheme: NewComponentTypes['Flex'],
|
|
46
|
+
props: FlexProps,
|
|
47
|
+
sharedTokens: SharedTokens
|
|
48
|
+
): FlexStyle => {
|
|
49
|
+
const { justifyItems, wrap, direction, gap } = props
|
|
50
|
+
|
|
51
|
+
// align-items css prop
|
|
52
|
+
// When flex direction is row, 'center' is the most useful default because it
|
|
53
|
+
// vertically aligns Items. For column direction, though, we want 'stretch'.
|
|
54
|
+
const alignItems =
|
|
55
|
+
props.alignItems ||
|
|
56
|
+
(direction === 'column' || direction === 'column-reverse'
|
|
57
|
+
? 'stretch'
|
|
58
|
+
: 'center')
|
|
59
|
+
const alignItemsValues = {
|
|
60
|
+
center: 'center',
|
|
61
|
+
start: 'flex-start',
|
|
62
|
+
end: 'flex-end',
|
|
63
|
+
stretch: 'stretch'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// justify-content css prop
|
|
67
|
+
const justifyItemsValues = {
|
|
68
|
+
start: 'flex-start',
|
|
69
|
+
end: 'flex-end',
|
|
70
|
+
center: 'center',
|
|
71
|
+
'space-around': 'space-around',
|
|
72
|
+
'space-between': 'space-between'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// wrap css prop
|
|
76
|
+
const wrapValues = {
|
|
77
|
+
wrap: 'wrap',
|
|
78
|
+
'wrap-reverse': 'wrap-reverse',
|
|
79
|
+
'no-wrap': undefined
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// flex-direction css props
|
|
83
|
+
const flexDirectionValues = {
|
|
84
|
+
column: 'column',
|
|
85
|
+
'column-reverse': 'column-reverse',
|
|
86
|
+
row: 'row',
|
|
87
|
+
'row-reverse': 'row-reverse'
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// gap css prop
|
|
91
|
+
const gapValues = makeThemeVars('gap', {
|
|
92
|
+
...sharedTokens.spacing,
|
|
93
|
+
...sharedTokens.legacy.spacing
|
|
94
|
+
})
|
|
95
|
+
const getGapValue = (gap: FlexProps['gap'], values: Record<string, string>) =>
|
|
96
|
+
getShorthandPropValue('Flex', values, gap, 'gap')
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
flex: {
|
|
100
|
+
label: 'flex',
|
|
101
|
+
fontFamily: componentTheme.fontFamily,
|
|
102
|
+
boxSizing: 'border-box',
|
|
103
|
+
alignItems: alignItemsValues[alignItems],
|
|
104
|
+
justifyContent: justifyItemsValues[justifyItems!],
|
|
105
|
+
flexWrap: wrapValues[wrap!],
|
|
106
|
+
flexDirection: flexDirectionValues[direction!],
|
|
107
|
+
gap: getGapValue(gap!, gapValues)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default generateStyle
|
package/src/exports/a.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export { Flex, FlexItem } from '../Flex/v1'
|
|
26
|
+
|
|
27
|
+
export type { FlexProps } from '../Flex/v1/props'
|
|
28
|
+
export type { FlexItemProps } from '../Flex/v1/Item/props'
|
package/src/exports/b.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export { Flex, FlexItem } from '../Flex/v2'
|
|
26
|
+
|
|
27
|
+
export type { FlexProps } from '../Flex/v2/props'
|
|
28
|
+
export type { FlexItemProps } from '../Flex/v2/Item/props'
|