@onesy/ui-react 1.0.205 → 1.0.208

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.
@@ -1,12 +1,15 @@
1
1
  import React from 'react';
2
2
  import { ISurface } from '../Surface/Surface';
3
+ import { IValueBreakpoints } from '../types';
4
+ export declare type IDividerAlignment = 'start' | 'center' | 'end';
5
+ export declare type IDividerOrientation = 'vertical' | 'horizontal';
3
6
  export declare type IDivider = ISurface & {
4
7
  inset?: boolean;
5
8
  middle?: boolean;
6
9
  padding?: number;
7
10
  opacity?: number;
8
- alignment?: 'start' | 'center' | 'end';
9
- orientation?: 'vertical' | 'horizontal';
11
+ alignment?: IDividerAlignment | Partial<Record<IValueBreakpoints, IDividerAlignment>>;
12
+ orientation?: IDividerOrientation | Partial<Record<IValueBreakpoints, IDividerOrientation>>;
10
13
  flex?: boolean;
11
14
  };
12
15
  declare const Divider: React.FC<IDivider>;
@@ -12,8 +12,10 @@ var _styleReact = require("@onesy/style-react");
12
12
  var _Type = _interopRequireDefault(require("../Type"));
13
13
  var _Surface = _interopRequireDefault(require("../Surface"));
14
14
  var _utils = require("../utils");
15
+ var _utils2 = require("@onesy/utils");
16
+ var _useMediaQuery = _interopRequireDefault(require("../useMediaQuery"));
15
17
  var _jsxRuntime = require("react/jsx-runtime");
16
- const _excluded = ["tonal", "color", "inset", "middle", "padding", "opacity", "alignment", "orientation", "flex", "Component", "className", "style", "children"];
18
+ const _excluded = ["ref", "tonal", "color", "inset", "middle", "padding", "opacity", "alignment", "orientation", "flex", "Component", "className", "style", "children"];
17
19
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
20
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
21
  const useStyle = (0, _styleReact.style)(theme => ({
@@ -134,14 +136,15 @@ const Divider = props_ => {
134
136
  const Type = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Type) || _Type.default;
135
137
  const Surface = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Surface) || _Surface.default;
136
138
  const {
139
+ ref,
137
140
  tonal = true,
138
141
  color = 'inverted',
139
142
  inset,
140
143
  middle,
141
144
  padding,
142
145
  opacity = theme.palette.visual_contrast.default.opacity.divider,
143
- alignment = 'center',
144
- orientation = 'horizontal',
146
+ alignment: alignmentProps,
147
+ orientation: orientationProps,
145
148
  flex,
146
149
  Component: Component_ = 'hr',
147
150
  className,
@@ -158,11 +161,36 @@ const Divider = props_ => {
158
161
  start: {},
159
162
  end: {}
160
163
  };
164
+ const refs = {
165
+ root: _react.default.useRef(undefined)
166
+ };
167
+ const keys = _react.default.useMemo(() => {
168
+ const result = [];
169
+ const items = [alignmentProps, orientationProps];
170
+ items.forEach(item => {
171
+ if ((0, _utils2.is)('object', item)) Object.keys(item).filter(key => theme.breakpoints.media[key]).forEach(key_0 => result.push(key_0));
172
+ });
173
+ return (0, _utils2.unique)(result);
174
+ }, [alignmentProps, orientationProps]);
175
+ const breakpoints = {};
176
+ keys.forEach(key_1 => {
177
+ breakpoints[key_1] = (0, _useMediaQuery.default)(theme.breakpoints.media[key_1], {
178
+ element: refs.root.current
179
+ });
180
+ });
181
+ const alignment = (0, _utils.valueBreakpoints)(alignmentProps, 'center', breakpoints, theme);
182
+ const orientation = (0, _utils.valueBreakpoints)(orientationProps, 'horizontal', breakpoints, theme);
161
183
  let Component = Component_;
162
184
  if (children && Component === 'hr') Component = 'div';
163
185
  if (alignment === 'start') styles.start.flexBasis = '15%';
164
186
  if (alignment === 'end') styles.end.flexBasis = '15%';
165
187
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Surface, _objectSpread(_objectSpread({
188
+ ref: item_0 => {
189
+ if (ref) {
190
+ if ((0, _utils2.is)('function', ref)) ref(item_0);else ref.current = item_0;
191
+ }
192
+ refs.root.current = item_0;
193
+ },
166
194
  version: "filled",
167
195
  tonal: tonal,
168
196
  color: color,
package/Select/Select.js CHANGED
@@ -364,6 +364,7 @@ const Select = props_ => {
364
364
  }))
365
365
  }), 1)] : [])];
366
366
  const sizeListItem = (MenuProps === null || MenuProps === void 0 ? void 0 : MenuProps.size) || size;
367
+ const noOptions = !(!!items.length || !!children.length);
367
368
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({
368
369
  gap: 0,
369
370
  direction: "column",
@@ -430,7 +431,7 @@ const Select = props_ => {
430
431
  justify: other.align,
431
432
  children: renderValues(value)
432
433
  })
433
- })), (!!items.length || !!children.length) && /*#__PURE__*/(0, _jsxRuntime.jsx)(Menu, _objectSpread(_objectSpread({
434
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(Menu, _objectSpread(_objectSpread({
434
435
  ref: refs.menu,
435
436
  open: open,
436
437
  portal: portal,
@@ -509,8 +510,12 @@ const Select = props_ => {
509
510
  overscrollBehavior: 'contain'
510
511
  }, MenuProps === null || MenuProps === void 0 || (_MenuProps$ListProps2 = MenuProps.ListProps) === null || _MenuProps$ListProps2 === void 0 ? void 0 : _MenuProps$ListProps2.style), ListProps === null || ListProps === void 0 ? void 0 : ListProps.style)
511
512
  }),
512
- style: _objectSpread(_objectSpread({}, styles.menu), MenuProps === null || MenuProps === void 0 ? void 0 : MenuProps.style),
513
- className: (0, _styleReact.classNames)(['onesy-Select-Menu', MenuProps === null || MenuProps === void 0 ? void 0 : MenuProps.className])
513
+ style: _objectSpread(_objectSpread(_objectSpread({}, noOptions && {
514
+ opacity: 0,
515
+ visibility: 'hidden',
516
+ pointerEvents: 'none'
517
+ }), styles.menu), MenuProps === null || MenuProps === void 0 ? void 0 : MenuProps.style),
518
+ className: (0, _styleReact.classNames)(['onesy-Select-Menu', noOptions && 'onesy-Select-Menu-no-options', MenuProps === null || MenuProps === void 0 ? void 0 : MenuProps.className])
514
519
  }))]
515
520
  }));
516
521
  };
@@ -1,13 +1,15 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- const _excluded = ["tonal", "color", "inset", "middle", "padding", "opacity", "alignment", "orientation", "flex", "Component", "className", "style", "children"];
3
+ const _excluded = ["ref", "tonal", "color", "inset", "middle", "padding", "opacity", "alignment", "orientation", "flex", "Component", "className", "style", "children"];
4
4
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  import React from 'react';
7
7
  import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
8
8
  import TypeElement from '../Type';
9
9
  import SurfaceElement from '../Surface';
10
- import { staticClassName } from '../utils';
10
+ import { staticClassName, valueBreakpoints } from '../utils';
11
+ import { is, unique } from '@onesy/utils';
12
+ import useMediaQuery from '../useMediaQuery';
11
13
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
12
14
  const useStyle = styleMethod(theme => ({
13
15
  root: {
@@ -126,14 +128,15 @@ const Divider = props_ => {
126
128
  const Type = theme?.elements?.Type || TypeElement;
127
129
  const Surface = theme?.elements?.Surface || SurfaceElement;
128
130
  const {
131
+ ref,
129
132
  tonal = true,
130
133
  color = 'inverted',
131
134
  inset,
132
135
  middle,
133
136
  padding,
134
137
  opacity = theme.palette.visual_contrast.default.opacity.divider,
135
- alignment = 'center',
136
- orientation = 'horizontal',
138
+ alignment: alignmentProps,
139
+ orientation: orientationProps,
137
140
  flex,
138
141
  Component: Component_ = 'hr',
139
142
  className,
@@ -150,11 +153,36 @@ const Divider = props_ => {
150
153
  start: {},
151
154
  end: {}
152
155
  };
156
+ const refs = {
157
+ root: React.useRef(undefined)
158
+ };
159
+ const keys = React.useMemo(() => {
160
+ const result = [];
161
+ const items = [alignmentProps, orientationProps];
162
+ items.forEach(item => {
163
+ if (is('object', item)) Object.keys(item).filter(key => theme.breakpoints.media[key]).forEach(key_0 => result.push(key_0));
164
+ });
165
+ return unique(result);
166
+ }, [alignmentProps, orientationProps]);
167
+ const breakpoints = {};
168
+ keys.forEach(key_1 => {
169
+ breakpoints[key_1] = useMediaQuery(theme.breakpoints.media[key_1], {
170
+ element: refs.root.current
171
+ });
172
+ });
173
+ const alignment = valueBreakpoints(alignmentProps, 'center', breakpoints, theme);
174
+ const orientation = valueBreakpoints(orientationProps, 'horizontal', breakpoints, theme);
153
175
  let Component = Component_;
154
176
  if (children && Component === 'hr') Component = 'div';
155
177
  if (alignment === 'start') styles.start.flexBasis = '15%';
156
178
  if (alignment === 'end') styles.end.flexBasis = '15%';
157
179
  return /*#__PURE__*/_jsx(Surface, _objectSpread(_objectSpread({
180
+ ref: item_0 => {
181
+ if (ref) {
182
+ if (is('function', ref)) ref(item_0);else ref.current = item_0;
183
+ }
184
+ refs.root.current = item_0;
185
+ },
158
186
  version: "filled",
159
187
  tonal: tonal,
160
188
  color: color,
@@ -351,6 +351,7 @@ const Select = props_ => {
351
351
  }))
352
352
  }), 1)] : [])];
353
353
  const sizeListItem = MenuProps?.size || size;
354
+ const noOptions = !(!!items.length || !!children.length);
354
355
  return /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({
355
356
  gap: 0,
356
357
  direction: "column",
@@ -417,7 +418,7 @@ const Select = props_ => {
417
418
  justify: other.align,
418
419
  children: renderValues(value)
419
420
  })
420
- })), (!!items.length || !!children.length) && /*#__PURE__*/_jsx(Menu, _objectSpread(_objectSpread({
421
+ })), /*#__PURE__*/_jsx(Menu, _objectSpread(_objectSpread({
421
422
  ref: refs.menu,
422
423
  open: open,
423
424
  portal: portal,
@@ -491,8 +492,12 @@ const Select = props_ => {
491
492
  overscrollBehavior: 'contain'
492
493
  }, MenuProps?.ListProps?.style), ListProps?.style)
493
494
  }),
494
- style: _objectSpread(_objectSpread({}, styles.menu), MenuProps?.style),
495
- className: classNames(['onesy-Select-Menu', MenuProps?.className])
495
+ style: _objectSpread(_objectSpread(_objectSpread({}, noOptions && {
496
+ opacity: 0,
497
+ visibility: 'hidden',
498
+ pointerEvents: 'none'
499
+ }), styles.menu), MenuProps?.style),
500
+ className: classNames(['onesy-Select-Menu', noOptions && 'onesy-Select-Menu-no-options', MenuProps?.className])
496
501
  }))]
497
502
  }));
498
503
  };
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license UiReact v1.0.204
1
+ /** @license UiReact v1.0.207
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license UiReact v1.0.204
1
+ /** @license UiReact v1.0.207
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onesy/ui-react",
3
- "version": "1.0.205",
3
+ "version": "1.0.208",
4
4
  "description": "UI for React",
5
5
  "repository": "https://github.com/onesy-me/onesy.git",
6
6
  "author": "Lazar Erić <lazareric1@proton.me>",