@hi-ui/grid 4.0.4 → 4.0.6
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 +17 -0
- package/lib/cjs/Grid.js +50 -95
- package/lib/cjs/context.js +0 -9
- package/lib/cjs/index.js +0 -3
- package/lib/cjs/styles/index.scss.js +2 -5
- package/lib/esm/Grid.js +47 -72
- package/lib/esm/context.js +0 -4
- package/lib/esm/index.js +1 -2
- package/lib/esm/styles/index.scss.js +2 -4
- package/lib/types/Grid.d.ts +1 -4
- package/package.json +8 -10
- package/LICENSE +0 -21
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @hi-ui/grid
|
|
2
|
+
|
|
3
|
+
## 4.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2672](https://github.com/XiaoMi/hiui/pull/2672) [`1ebe27830`](https://github.com/XiaoMi/hiui/commit/1ebe2783098b3a8cd980bd10076d67635463800e) Thanks [@zyprepare](https://github.com/zyprepare)! - build: 升级到 rollup3,重新构建发布组件
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`1ebe27830`](https://github.com/XiaoMi/hiui/commit/1ebe2783098b3a8cd980bd10076d67635463800e)]:
|
|
10
|
+
- @hi-ui/core@4.0.6
|
|
11
|
+
- @hi-ui/classname@4.0.2
|
|
12
|
+
- @hi-ui/env@4.0.2
|
|
13
|
+
- @hi-ui/type-assertion@4.0.2
|
|
14
|
+
|
|
15
|
+
## 4.0.5
|
|
16
|
+
|
|
17
|
+
更新版本为 4.0.5
|
package/lib/cjs/Grid.js
CHANGED
|
@@ -9,77 +9,50 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(exports, '__esModule', {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
|
|
18
12
|
var tslib = require('tslib');
|
|
19
|
-
|
|
20
13
|
var React = require('react');
|
|
21
|
-
|
|
22
14
|
var classname = require('@hi-ui/classname');
|
|
23
|
-
|
|
24
15
|
var env = require('@hi-ui/env');
|
|
25
|
-
|
|
26
16
|
var context = require('./context.js');
|
|
27
|
-
|
|
28
17
|
var typeAssertion = require('@hi-ui/type-assertion');
|
|
29
|
-
|
|
30
|
-
function _interopDefaultLegacy(e) {
|
|
31
|
-
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
|
32
|
-
'default': e
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
37
|
-
|
|
38
18
|
var rowPrefix = classname.getPrefixCls('grid-row');
|
|
39
19
|
var gutterNameVar = classname.getPrefixStyleVar('grid-row-gutter');
|
|
40
20
|
var columnsNameVar = classname.getPrefixStyleVar('grid-row-columns');
|
|
41
|
-
var gapNameVar = classname.getPrefixStyleVar('grid-row-gap');
|
|
42
|
-
|
|
43
|
-
var DEFAULT_ROW_GAP = 16;
|
|
44
|
-
|
|
21
|
+
var gapNameVar = classname.getPrefixStyleVar('grid-row-gap');
|
|
22
|
+
// Row 与 Row 默认间距
|
|
23
|
+
var DEFAULT_ROW_GAP = 16;
|
|
24
|
+
// Row 内每项 Col 默认间距
|
|
45
25
|
var DEFAULT_GUTTER_GAP = 16;
|
|
46
26
|
/**
|
|
47
|
-
*
|
|
27
|
+
* 栅格
|
|
48
28
|
*/
|
|
49
|
-
|
|
50
29
|
var Row = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
51
30
|
var _Object$assign;
|
|
52
|
-
|
|
53
31
|
var _a$prefixCls = _a.prefixCls,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
32
|
+
prefixCls = _a$prefixCls === void 0 ? rowPrefix : _a$prefixCls,
|
|
33
|
+
className = _a.className,
|
|
34
|
+
children = _a.children,
|
|
35
|
+
styleProp = _a.style,
|
|
36
|
+
justifyContent = _a.justify,
|
|
37
|
+
_a$columns = _a.columns,
|
|
38
|
+
columns = _a$columns === void 0 ? 24 : _a$columns,
|
|
39
|
+
_a$rowGap = _a.rowGap,
|
|
40
|
+
rowGap = _a$rowGap === void 0 ? DEFAULT_ROW_GAP : _a$rowGap,
|
|
41
|
+
_a$gutter = _a.gutter,
|
|
42
|
+
gutterProp = _a$gutter === void 0 ? false : _a$gutter,
|
|
43
|
+
rest = tslib.__rest(_a, ["prefixCls", "className", "children", "style", "justify", "columns", "rowGap", "gutter"]);
|
|
67
44
|
var gutter = React.useMemo(function () {
|
|
68
45
|
if (typeof gutterProp === 'boolean') {
|
|
69
46
|
return gutterProp ? DEFAULT_GUTTER_GAP : 0;
|
|
70
47
|
}
|
|
71
|
-
|
|
72
48
|
if (typeAssertion.isNumeric(gutterProp)) {
|
|
73
49
|
var gap = Number(gutterProp);
|
|
74
|
-
|
|
75
50
|
if (gap < 0) {
|
|
76
51
|
console.info('Warning: The gutter should be a positive number.');
|
|
77
52
|
gap = DEFAULT_GUTTER_GAP;
|
|
78
53
|
}
|
|
79
|
-
|
|
80
54
|
return gap;
|
|
81
55
|
}
|
|
82
|
-
|
|
83
56
|
return 0;
|
|
84
57
|
}, [gutterProp]);
|
|
85
58
|
var justifyContentStyle = calcResponsiveGrid({
|
|
@@ -100,51 +73,41 @@ var Row = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
100
73
|
columns: columns
|
|
101
74
|
};
|
|
102
75
|
}, [columns]);
|
|
103
|
-
return /*#__PURE__*/
|
|
76
|
+
return /*#__PURE__*/React.createElement(context.GridProvider, {
|
|
104
77
|
value: providedContext
|
|
105
|
-
}, /*#__PURE__*/
|
|
78
|
+
}, /*#__PURE__*/React.createElement("div", Object.assign({
|
|
106
79
|
ref: ref,
|
|
107
80
|
className: cls,
|
|
108
81
|
style: style
|
|
109
82
|
}, rest), children));
|
|
110
83
|
});
|
|
111
|
-
|
|
112
84
|
if (env.__DEV__) {
|
|
113
85
|
Row.displayName = 'Row';
|
|
114
86
|
}
|
|
115
|
-
|
|
116
|
-
|
|
87
|
+
var colPrefix = classname.getPrefixCls('grid-col');
|
|
88
|
+
// const spanNameVar = getPrefixStyleVar('grid-col-span')
|
|
117
89
|
// const offsetNameVar = getPrefixStyleVar('grid-col-offset')
|
|
118
|
-
|
|
119
90
|
var getGridStyleVar = function getGridStyleVar(prop, size) {
|
|
120
91
|
if (size) {
|
|
121
92
|
return classname.getPrefixStyleVar('grid-' + prop + '-' + size);
|
|
122
93
|
}
|
|
123
|
-
|
|
124
94
|
return classname.getPrefixStyleVar('grid-' + prop);
|
|
125
95
|
};
|
|
126
|
-
/**
|
|
127
|
-
* TODO: What is Grid Col
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
96
|
var Col = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
132
97
|
var _a$prefixCls2 = _a.prefixCls,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
98
|
+
prefixCls = _a$prefixCls2 === void 0 ? colPrefix : _a$prefixCls2,
|
|
99
|
+
className = _a.className,
|
|
100
|
+
children = _a.children,
|
|
101
|
+
styleProp = _a.style,
|
|
102
|
+
spanProp = _a.span,
|
|
103
|
+
_a$offset = _a.offset,
|
|
104
|
+
offsetProp = _a$offset === void 0 ? 0 : _a$offset,
|
|
105
|
+
justifyContent = _a.justify,
|
|
106
|
+
order = _a.order,
|
|
107
|
+
rest = tslib.__rest(_a, ["prefixCls", "className", "children", "style", "span", "offset", "justify", "order"]);
|
|
144
108
|
var _useGridContext = context.useGridContext(),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
109
|
+
_useGridContext$colum = _useGridContext.columns,
|
|
110
|
+
columns = _useGridContext$colum === void 0 ? 24 : _useGridContext$colum;
|
|
148
111
|
var spanStyle = calcResponsiveGrid({
|
|
149
112
|
name: 'col-span',
|
|
150
113
|
value: spanProp,
|
|
@@ -186,55 +149,50 @@ var Col = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
186
149
|
});
|
|
187
150
|
var style = Object.assign(justifyContent ? Object.assign(Object.assign(Object.assign({}, styleProp), {
|
|
188
151
|
display: 'flex'
|
|
189
|
-
}), justifyContentStyle) : Object.assign({}, styleProp), spanStyle, offsetStyle, orderStyle
|
|
152
|
+
}), justifyContentStyle) : Object.assign({}, styleProp), spanStyle, offsetStyle, orderStyle
|
|
153
|
+
// {
|
|
190
154
|
// [spanNameVar]: span === null ? 'unset' : `calc(${span} / ${columns} * 100%)`,
|
|
191
155
|
// [offsetNameVar]: `calc(${offset} / ${columns} * 100%)`,
|
|
192
156
|
// }
|
|
193
157
|
);
|
|
158
|
+
|
|
194
159
|
var cls = classname.cx(prefixCls, className);
|
|
195
|
-
return /*#__PURE__*/
|
|
160
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
196
161
|
ref: ref,
|
|
197
162
|
className: cls,
|
|
198
163
|
style: style
|
|
199
164
|
}, rest), children);
|
|
200
165
|
});
|
|
201
|
-
|
|
202
166
|
if (env.__DEV__) {
|
|
203
167
|
Col.displayName = 'Col';
|
|
204
168
|
}
|
|
205
|
-
|
|
206
169
|
var setGridSpan = function setGridSpan(value, min, max, propName) {
|
|
207
170
|
var nextValue = Number(value);
|
|
208
|
-
|
|
209
171
|
if (env.__DEV__) {
|
|
210
172
|
env.invariant(nextValue >= min && nextValue <= max, "Please set " + propName + " in the range [" + min + ", " + max + "] When using Grid component.");
|
|
211
173
|
}
|
|
212
|
-
|
|
213
174
|
if (nextValue < 0) nextValue = 0;
|
|
214
175
|
if (nextValue > max) nextValue = max;
|
|
215
176
|
return nextValue;
|
|
216
177
|
};
|
|
217
|
-
|
|
218
178
|
var GRID_SIZE_ARRAY = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
219
|
-
|
|
220
179
|
function calcResponsiveGrid(_ref) {
|
|
221
180
|
var value = _ref.value,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
181
|
+
defaultValue = _ref.defaultValue,
|
|
182
|
+
allowSet = _ref.allowSet,
|
|
183
|
+
setValue = _ref.setValue,
|
|
184
|
+
name = _ref.name,
|
|
185
|
+
noneCallback = _ref.noneCallback;
|
|
227
186
|
var style = {};
|
|
228
|
-
|
|
229
187
|
if (typeAssertion.isObject(value)) {
|
|
230
188
|
var prevSpan;
|
|
231
189
|
GRID_SIZE_ARRAY.forEach(function (key) {
|
|
232
|
-
var varName = getGridStyleVar(name, key);
|
|
233
|
-
|
|
234
|
-
var sizeValue = value[key];
|
|
235
|
-
|
|
236
|
-
style[varName] = allowSet(sizeValue) ? setValue(sizeValue) : prevSpan;
|
|
237
|
-
|
|
190
|
+
var varName = getGridStyleVar(name, key);
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
var sizeValue = value[key];
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
style[varName] = allowSet(sizeValue) ? setValue(sizeValue) : prevSpan;
|
|
195
|
+
// @ts-ignore
|
|
238
196
|
prevSpan = style[varName];
|
|
239
197
|
});
|
|
240
198
|
} else {
|
|
@@ -247,14 +205,11 @@ function calcResponsiveGrid(_ref) {
|
|
|
247
205
|
value = defaultValue;
|
|
248
206
|
}
|
|
249
207
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
208
|
+
var varName = getGridStyleVar(name);
|
|
209
|
+
// @ts-ignore
|
|
253
210
|
style[varName] = value;
|
|
254
211
|
}
|
|
255
|
-
|
|
256
212
|
return style;
|
|
257
213
|
}
|
|
258
|
-
|
|
259
214
|
exports.Col = Col;
|
|
260
215
|
exports.Row = Row;
|
package/lib/cjs/context.js
CHANGED
|
@@ -9,24 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
Object.defineProperty(exports, '__esModule', {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
|
|
16
12
|
var React = require('react');
|
|
17
|
-
|
|
18
13
|
var gridContext = /*#__PURE__*/React.createContext({});
|
|
19
14
|
var GridProvider = gridContext.Provider;
|
|
20
|
-
|
|
21
15
|
var useGridContext = function useGridContext() {
|
|
22
16
|
var context = React.useContext(gridContext);
|
|
23
|
-
|
|
24
17
|
if (!context) {
|
|
25
18
|
throw new Error('The GridContext context is not defined, Maybe it should be wrapped in Row.');
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
return context;
|
|
29
21
|
};
|
|
30
|
-
|
|
31
22
|
exports.GridProvider = GridProvider;
|
|
32
23
|
exports.useGridContext = useGridContext;
|
package/lib/cjs/index.js
CHANGED
|
@@ -12,10 +12,7 @@
|
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
|
13
13
|
value: true
|
|
14
14
|
});
|
|
15
|
-
var css_248z = ".hi-v4-grid-row {position: relative;-webkit-box-sizing: border-box;box-sizing: border-box;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: horizontal;-webkit-box-direction: normal;-ms-flex-direction: row;flex-direction: row;-ms-flex-wrap: wrap;flex-wrap: wrap;row-gap: var(--hi-v4-grid-row-gap);margin-left: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);margin-right: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);-webkit-box-pack: var(--hi-v4-grid-row-justify);-ms-flex-pack: var(--hi-v4-grid-row-justify);justify-content: var(--hi-v4-grid-row-justify);
|
|
16
|
-
|
|
17
|
-
var __styleInject__ = require('inject-head-style')["default"];
|
|
18
|
-
|
|
15
|
+
var css_248z = ".hi-v4-grid-row {position: relative;-webkit-box-sizing: border-box;box-sizing: border-box;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: horizontal;-webkit-box-direction: normal;-ms-flex-direction: row;flex-direction: row;-ms-flex-wrap: wrap;flex-wrap: wrap;row-gap: var(--hi-v4-grid-row-gap);margin-left: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);margin-right: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);-webkit-box-pack: var(--hi-v4-grid-row-justify);-ms-flex-pack: var(--hi-v4-grid-row-justify);justify-content: var(--hi-v4-grid-row-justify);}.hi-v4-grid-row + .hi-v4-grid-row {margin-top: var(--hi-v4-grid-row-gap);}.hi-v4-grid-col {-webkit-box-sizing: border-box;box-sizing: border-box;-webkit-box-flex: 0;-ms-flex-positive: 0;flex-grow: 0;-ms-flex-negative: 0;flex-shrink: 0;min-width: 1px;padding-left: calc(var(--hi-v4-grid-row-gutter) / 2);padding-right: calc(var(--hi-v4-grid-row-gutter) / 2);-ms-flex-preferred-size: calc(var(--hi-v4-grid-col-span) / var(--hi-v4-grid-row-columns) * 100%);flex-basis: calc(var(--hi-v4-grid-col-span) / var(--hi-v4-grid-row-columns) * 100%);max-width: calc(var(--hi-v4-grid-col-span) / var(--hi-v4-grid-row-columns) * 100%);-webkit-margin-start: calc(var(--hi-v4-grid-col-offset) / var(--hi-v4-grid-row-columns) * 100%);margin-inline-start: calc(var(--hi-v4-grid-col-offset) / var(--hi-v4-grid-row-columns) * 100%);-webkit-box-ordinal-group: NaN;-ms-flex-order: var(--hi-v4-grid-col-order);order: var(--hi-v4-grid-col-order);-webkit-box-pack: var(--hi-v4-grid-col-justify);-ms-flex-pack: var(--hi-v4-grid-col-justify);justify-content: var(--hi-v4-grid-col-justify);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-xs);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-xs);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-xs);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-xs);}.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-xs);}@media only screen and (min-width: 576px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-sm);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-sm);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-sm);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-sm);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-sm);}}@media only screen and (min-width: 768px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-md);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-md);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-md);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-md);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-md);}}@media only screen and (min-width: 992px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-lg);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-lg);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-lg);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-lg);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-lg);}}@media only screen and (min-width: 1200px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-xl);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-xl);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-xl);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-xl);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-xl);}}";
|
|
16
|
+
var __styleInject__ = require('style-inject')["default"];
|
|
19
17
|
__styleInject__(css_248z);
|
|
20
|
-
|
|
21
18
|
exports["default"] = css_248z;
|
package/lib/esm/Grid.js
CHANGED
|
@@ -16,48 +16,41 @@ import { isNumeric, isObject, isString } from '@hi-ui/type-assertion';
|
|
|
16
16
|
var rowPrefix = getPrefixCls('grid-row');
|
|
17
17
|
var gutterNameVar = getPrefixStyleVar('grid-row-gutter');
|
|
18
18
|
var columnsNameVar = getPrefixStyleVar('grid-row-columns');
|
|
19
|
-
var gapNameVar = getPrefixStyleVar('grid-row-gap');
|
|
20
|
-
|
|
21
|
-
var DEFAULT_ROW_GAP = 16;
|
|
22
|
-
|
|
19
|
+
var gapNameVar = getPrefixStyleVar('grid-row-gap');
|
|
20
|
+
// Row 与 Row 默认间距
|
|
21
|
+
var DEFAULT_ROW_GAP = 16;
|
|
22
|
+
// Row 内每项 Col 默认间距
|
|
23
23
|
var DEFAULT_GUTTER_GAP = 16;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* 栅格
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
27
|
var Row = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
29
28
|
var _Object$assign;
|
|
30
|
-
|
|
31
29
|
var _a$prefixCls = _a.prefixCls,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
prefixCls = _a$prefixCls === void 0 ? rowPrefix : _a$prefixCls,
|
|
31
|
+
className = _a.className,
|
|
32
|
+
children = _a.children,
|
|
33
|
+
styleProp = _a.style,
|
|
34
|
+
justifyContent = _a.justify,
|
|
35
|
+
_a$columns = _a.columns,
|
|
36
|
+
columns = _a$columns === void 0 ? 24 : _a$columns,
|
|
37
|
+
_a$rowGap = _a.rowGap,
|
|
38
|
+
rowGap = _a$rowGap === void 0 ? DEFAULT_ROW_GAP : _a$rowGap,
|
|
39
|
+
_a$gutter = _a.gutter,
|
|
40
|
+
gutterProp = _a$gutter === void 0 ? false : _a$gutter,
|
|
41
|
+
rest = __rest(_a, ["prefixCls", "className", "children", "style", "justify", "columns", "rowGap", "gutter"]);
|
|
45
42
|
var gutter = useMemo(function () {
|
|
46
43
|
if (typeof gutterProp === 'boolean') {
|
|
47
44
|
return gutterProp ? DEFAULT_GUTTER_GAP : 0;
|
|
48
45
|
}
|
|
49
|
-
|
|
50
46
|
if (isNumeric(gutterProp)) {
|
|
51
47
|
var gap = Number(gutterProp);
|
|
52
|
-
|
|
53
48
|
if (gap < 0) {
|
|
54
49
|
console.info('Warning: The gutter should be a positive number.');
|
|
55
50
|
gap = DEFAULT_GUTTER_GAP;
|
|
56
51
|
}
|
|
57
|
-
|
|
58
52
|
return gap;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
return 0;
|
|
62
55
|
}, [gutterProp]);
|
|
63
56
|
var justifyContentStyle = calcResponsiveGrid({
|
|
@@ -86,43 +79,33 @@ var Row = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
86
79
|
style: style
|
|
87
80
|
}, rest), children));
|
|
88
81
|
});
|
|
89
|
-
|
|
90
82
|
if (__DEV__) {
|
|
91
83
|
Row.displayName = 'Row';
|
|
92
84
|
}
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
var colPrefix = getPrefixCls('grid-col');
|
|
86
|
+
// const spanNameVar = getPrefixStyleVar('grid-col-span')
|
|
95
87
|
// const offsetNameVar = getPrefixStyleVar('grid-col-offset')
|
|
96
|
-
|
|
97
88
|
var getGridStyleVar = function getGridStyleVar(prop, size) {
|
|
98
89
|
if (size) {
|
|
99
90
|
return getPrefixStyleVar('grid-' + prop + '-' + size);
|
|
100
91
|
}
|
|
101
|
-
|
|
102
92
|
return getPrefixStyleVar('grid-' + prop);
|
|
103
93
|
};
|
|
104
|
-
/**
|
|
105
|
-
* TODO: What is Grid Col
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
94
|
var Col = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
110
95
|
var _a$prefixCls2 = _a.prefixCls,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
96
|
+
prefixCls = _a$prefixCls2 === void 0 ? colPrefix : _a$prefixCls2,
|
|
97
|
+
className = _a.className,
|
|
98
|
+
children = _a.children,
|
|
99
|
+
styleProp = _a.style,
|
|
100
|
+
spanProp = _a.span,
|
|
101
|
+
_a$offset = _a.offset,
|
|
102
|
+
offsetProp = _a$offset === void 0 ? 0 : _a$offset,
|
|
103
|
+
justifyContent = _a.justify,
|
|
104
|
+
order = _a.order,
|
|
105
|
+
rest = __rest(_a, ["prefixCls", "className", "children", "style", "span", "offset", "justify", "order"]);
|
|
122
106
|
var _useGridContext = useGridContext(),
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
107
|
+
_useGridContext$colum = _useGridContext.columns,
|
|
108
|
+
columns = _useGridContext$colum === void 0 ? 24 : _useGridContext$colum;
|
|
126
109
|
var spanStyle = calcResponsiveGrid({
|
|
127
110
|
name: 'col-span',
|
|
128
111
|
value: spanProp,
|
|
@@ -164,11 +147,13 @@ var Col = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
164
147
|
});
|
|
165
148
|
var style = Object.assign(justifyContent ? Object.assign(Object.assign(Object.assign({}, styleProp), {
|
|
166
149
|
display: 'flex'
|
|
167
|
-
}), justifyContentStyle) : Object.assign({}, styleProp), spanStyle, offsetStyle, orderStyle
|
|
150
|
+
}), justifyContentStyle) : Object.assign({}, styleProp), spanStyle, offsetStyle, orderStyle
|
|
151
|
+
// {
|
|
168
152
|
// [spanNameVar]: span === null ? 'unset' : `calc(${span} / ${columns} * 100%)`,
|
|
169
153
|
// [offsetNameVar]: `calc(${offset} / ${columns} * 100%)`,
|
|
170
154
|
// }
|
|
171
155
|
);
|
|
156
|
+
|
|
172
157
|
var cls = cx(prefixCls, className);
|
|
173
158
|
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
174
159
|
ref: ref,
|
|
@@ -176,43 +161,36 @@ var Col = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
176
161
|
style: style
|
|
177
162
|
}, rest), children);
|
|
178
163
|
});
|
|
179
|
-
|
|
180
164
|
if (__DEV__) {
|
|
181
165
|
Col.displayName = 'Col';
|
|
182
166
|
}
|
|
183
|
-
|
|
184
167
|
var setGridSpan = function setGridSpan(value, min, max, propName) {
|
|
185
168
|
var nextValue = Number(value);
|
|
186
|
-
|
|
187
169
|
if (__DEV__) {
|
|
188
170
|
invariant(nextValue >= min && nextValue <= max, "Please set " + propName + " in the range [" + min + ", " + max + "] When using Grid component.");
|
|
189
171
|
}
|
|
190
|
-
|
|
191
172
|
if (nextValue < 0) nextValue = 0;
|
|
192
173
|
if (nextValue > max) nextValue = max;
|
|
193
174
|
return nextValue;
|
|
194
175
|
};
|
|
195
|
-
|
|
196
176
|
var GRID_SIZE_ARRAY = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
197
|
-
|
|
198
177
|
function calcResponsiveGrid(_ref) {
|
|
199
178
|
var value = _ref.value,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
179
|
+
defaultValue = _ref.defaultValue,
|
|
180
|
+
allowSet = _ref.allowSet,
|
|
181
|
+
setValue = _ref.setValue,
|
|
182
|
+
name = _ref.name,
|
|
183
|
+
noneCallback = _ref.noneCallback;
|
|
205
184
|
var style = {};
|
|
206
|
-
|
|
207
185
|
if (isObject(value)) {
|
|
208
186
|
var prevSpan;
|
|
209
187
|
GRID_SIZE_ARRAY.forEach(function (key) {
|
|
210
|
-
var varName = getGridStyleVar(name, key);
|
|
211
|
-
|
|
212
|
-
var sizeValue = value[key];
|
|
213
|
-
|
|
214
|
-
style[varName] = allowSet(sizeValue) ? setValue(sizeValue) : prevSpan;
|
|
215
|
-
|
|
188
|
+
var varName = getGridStyleVar(name, key);
|
|
189
|
+
// @ts-ignore
|
|
190
|
+
var sizeValue = value[key];
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
style[varName] = allowSet(sizeValue) ? setValue(sizeValue) : prevSpan;
|
|
193
|
+
// @ts-ignore
|
|
216
194
|
prevSpan = style[varName];
|
|
217
195
|
});
|
|
218
196
|
} else {
|
|
@@ -225,13 +203,10 @@ function calcResponsiveGrid(_ref) {
|
|
|
225
203
|
value = defaultValue;
|
|
226
204
|
}
|
|
227
205
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
206
|
+
var varName = getGridStyleVar(name);
|
|
207
|
+
// @ts-ignore
|
|
231
208
|
style[varName] = value;
|
|
232
209
|
}
|
|
233
|
-
|
|
234
210
|
return style;
|
|
235
211
|
}
|
|
236
|
-
|
|
237
212
|
export { Col, Row };
|
package/lib/esm/context.js
CHANGED
|
@@ -10,15 +10,11 @@
|
|
|
10
10
|
import { useContext, createContext } from 'react';
|
|
11
11
|
var gridContext = /*#__PURE__*/createContext({});
|
|
12
12
|
var GridProvider = gridContext.Provider;
|
|
13
|
-
|
|
14
13
|
var useGridContext = function useGridContext() {
|
|
15
14
|
var context = useContext(gridContext);
|
|
16
|
-
|
|
17
15
|
if (!context) {
|
|
18
16
|
throw new Error('The GridContext context is not defined, Maybe it should be wrapped in Row.');
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
return context;
|
|
22
19
|
};
|
|
23
|
-
|
|
24
20
|
export { GridProvider, useGridContext };
|
package/lib/esm/index.js
CHANGED
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
|
-
import __styleInject__ from 'inject
|
|
11
|
-
var css_248z = ".hi-v4-grid-row {position: relative;-webkit-box-sizing: border-box;box-sizing: border-box;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: horizontal;-webkit-box-direction: normal;-ms-flex-direction: row;flex-direction: row;-ms-flex-wrap: wrap;flex-wrap: wrap;row-gap: var(--hi-v4-grid-row-gap);margin-left: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);margin-right: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);-webkit-box-pack: var(--hi-v4-grid-row-justify);-ms-flex-pack: var(--hi-v4-grid-row-justify);justify-content: var(--hi-v4-grid-row-justify);
|
|
12
|
-
|
|
10
|
+
import __styleInject__ from 'style-inject';
|
|
11
|
+
var css_248z = ".hi-v4-grid-row {position: relative;-webkit-box-sizing: border-box;box-sizing: border-box;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: horizontal;-webkit-box-direction: normal;-ms-flex-direction: row;flex-direction: row;-ms-flex-wrap: wrap;flex-wrap: wrap;row-gap: var(--hi-v4-grid-row-gap);margin-left: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);margin-right: calc(-1 * var(--hi-v4-grid-row-gutter) / 2);-webkit-box-pack: var(--hi-v4-grid-row-justify);-ms-flex-pack: var(--hi-v4-grid-row-justify);justify-content: var(--hi-v4-grid-row-justify);}.hi-v4-grid-row + .hi-v4-grid-row {margin-top: var(--hi-v4-grid-row-gap);}.hi-v4-grid-col {-webkit-box-sizing: border-box;box-sizing: border-box;-webkit-box-flex: 0;-ms-flex-positive: 0;flex-grow: 0;-ms-flex-negative: 0;flex-shrink: 0;min-width: 1px;padding-left: calc(var(--hi-v4-grid-row-gutter) / 2);padding-right: calc(var(--hi-v4-grid-row-gutter) / 2);-ms-flex-preferred-size: calc(var(--hi-v4-grid-col-span) / var(--hi-v4-grid-row-columns) * 100%);flex-basis: calc(var(--hi-v4-grid-col-span) / var(--hi-v4-grid-row-columns) * 100%);max-width: calc(var(--hi-v4-grid-col-span) / var(--hi-v4-grid-row-columns) * 100%);-webkit-margin-start: calc(var(--hi-v4-grid-col-offset) / var(--hi-v4-grid-row-columns) * 100%);margin-inline-start: calc(var(--hi-v4-grid-col-offset) / var(--hi-v4-grid-row-columns) * 100%);-webkit-box-ordinal-group: NaN;-ms-flex-order: var(--hi-v4-grid-col-order);order: var(--hi-v4-grid-col-order);-webkit-box-pack: var(--hi-v4-grid-col-justify);-ms-flex-pack: var(--hi-v4-grid-col-justify);justify-content: var(--hi-v4-grid-col-justify);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-xs);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-xs);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-xs);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-xs);}.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-xs);}@media only screen and (min-width: 576px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-sm);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-sm);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-sm);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-sm);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-sm);}}@media only screen and (min-width: 768px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-md);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-md);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-md);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-md);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-md);}}@media only screen and (min-width: 992px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-lg);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-lg);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-lg);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-lg);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-lg);}}@media only screen and (min-width: 1200px) {.hi-v4-grid-row {--hi-v4-grid-row-justify: var(--hi-v4-grid-row-justify-xl);}.hi-v4-grid-col {--hi-v4-grid-col-span: var(--hi-v4-grid-col-span-xl);--hi-v4-grid-col-offset: var(--hi-v4-grid-col-offset-xl);--hi-v4-grid-col-order: var(--hi-v4-grid-col-order-xl);--hi-v4-grid-col-justify: var(--hi-v4-grid-col-justify-xl);}}";
|
|
13
12
|
__styleInject__(css_248z);
|
|
14
|
-
|
|
15
13
|
export { css_248z as default };
|
package/lib/types/Grid.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { HiBaseHTMLProps } from '@hi-ui/core';
|
|
3
3
|
import { GridJustifyEnum, GridResponsiveSize } from './types';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 栅格
|
|
6
6
|
*/
|
|
7
7
|
export declare const Row: React.ForwardRefExoticComponent<RowProps & React.RefAttributes<HTMLDivElement | null>>;
|
|
8
8
|
export interface RowProps extends HiBaseHTMLProps<'div'> {
|
|
@@ -23,9 +23,6 @@ export interface RowProps extends HiBaseHTMLProps<'div'> {
|
|
|
23
23
|
*/
|
|
24
24
|
rowGap?: number;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
* TODO: What is Grid Col
|
|
28
|
-
*/
|
|
29
26
|
export declare const Col: React.ForwardRefExoticComponent<ColProps & React.RefAttributes<HTMLDivElement | null>>;
|
|
30
27
|
export interface ColProps extends HiBaseHTMLProps<'div'> {
|
|
31
28
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hi-ui/grid",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "HiUI <mi-hiui@xiaomi.com>",
|
|
@@ -43,21 +43,19 @@
|
|
|
43
43
|
"url": "https://github.com/XiaoMi/hiui/issues"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@hi-ui/classname": "^4.0.
|
|
47
|
-
"@hi-ui/env": "^4.0.
|
|
48
|
-
"@hi-ui/type-assertion": "^4.0.
|
|
46
|
+
"@hi-ui/classname": "^4.0.2",
|
|
47
|
+
"@hi-ui/env": "^4.0.2",
|
|
48
|
+
"@hi-ui/type-assertion": "^4.0.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@hi-ui/core": ">=4.0.
|
|
51
|
+
"@hi-ui/core": ">=4.0.6",
|
|
52
52
|
"react": ">=16.8.6",
|
|
53
53
|
"react-dom": ">=16.8.6"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@hi-ui/core": "^4.0.
|
|
57
|
-
"@hi-ui/core-css": "^4.
|
|
58
|
-
"@hi-ui/hi-build": "^4.0.1",
|
|
56
|
+
"@hi-ui/core": "^4.0.6",
|
|
57
|
+
"@hi-ui/core-css": "^4.1.3",
|
|
59
58
|
"react": "^17.0.1",
|
|
60
59
|
"react-dom": "^17.0.1"
|
|
61
|
-
}
|
|
62
|
-
"gitHead": "f5dedca5447a3a7bfaf937bce1c718d8a029efad"
|
|
60
|
+
}
|
|
63
61
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Xiaomi
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|