diginet-core-ui 1.3.90 → 1.3.91

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,14 +1,14 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useMemo, useState, useEffect, useRef, forwardRef, Fragment, useImperativeHandle } from 'react';
4
- import { render } from 'react-dom';
5
- import PropTypes from 'prop-types';
6
- import { jsx, css } from '@emotion/core';
7
- import { Accordion, AccordionSummary, AccordionDetails, Typography, Checkbox, Divider, InputBase, ButtonIcon } from '..';
8
- import { classNames, mapParent, randomString, removeUnicode } from "../../utils";
3
+ import { css, jsx } from '@emotion/core';
4
+ import { Accordion, AccordionDetails, AccordionSummary, ButtonIcon, Checkbox, Divider, InputBase, Typography } from "./..";
9
5
  import { getGlobal } from "../../global";
10
- import { itemsCenter, boxBorder, cursorPointer, displayBlock, displayInlineBlock, flexRow, positionRelative } from "../../styles/general";
11
- import theme from "../../theme/settings";
6
+ import PropTypes from 'prop-types';
7
+ import { forwardRef, Fragment, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
8
+ import { render } from 'react-dom';
9
+ import { bgColor, borderRadius, boxBorder, cursorNotAllowed, cursorPointer, displayBlock, displayInlineBlock, flexRow, itemsCenter, mgb, mgl, mgr, parseHeight, parseMinHeight, parseWidth, pd, pdl, positionRelative, textLeft } from "../../styles/general";
10
+ import { useTheme } from "../../theme";
11
+ import { classNames, mapParent, randomString, refType as ref, removeUnicode } from "../../utils";
12
12
  const {
13
13
  colors: {
14
14
  system: {
@@ -22,9 +22,8 @@ const {
22
22
  text: {
23
23
  main: textMain
24
24
  }
25
- },
26
- spacing
27
- } = theme;
25
+ }
26
+ } = useTheme();
28
27
  const separatorPattern = /\{\w+\}/g;
29
28
  const currentValue = {},
30
29
  itemsRenderAsync = {};
@@ -61,6 +60,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
61
60
  valueExpr,
62
61
  ...props
63
62
  }, reference) => {
63
+ if (!reference) reference = useRef(null);
64
64
  const ref = useRef(null);
65
65
  const selectAllRef = useRef(null);
66
66
  const inputValueRef = useRef(null);
@@ -319,8 +319,8 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
319
319
  const checkBoxEl = currentTarget.querySelector('.TreeView-Item-Checkbox');
320
320
  if (multiple) {
321
321
  var _value;
322
- let checked = false;
323
- let inputEl = null;
322
+ let checked;
323
+ let inputEl;
324
324
  // Click on text (not checkbox)
325
325
  if (!checkBoxEl.contains(target)) {
326
326
  inputEl = checkBoxEl.querySelector('input');
@@ -604,7 +604,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
604
604
  }
605
605
  }, jsx("div", {
606
606
  className: 'TreeView-Item'
607
- }, (selectBox || multiple) && jsx("span", {
607
+ }, selectBox || multiple ? jsx("span", {
608
608
  className: 'TreeView-Item-Checkbox'
609
609
  }, jsx(Checkbox, {
610
610
  forTreeView: true,
@@ -612,19 +612,19 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
612
612
  value: typeof data === 'object' ? data[valueExpr] : data,
613
613
  stopPropagation: false,
614
614
  disabled: disabled
615
- })), renderContent(data, keyArr, index))), jsx(AccordionDetails, {
615
+ })) : null, renderContent(data, keyArr, index))), jsx(AccordionDetails, {
616
616
  id: id
617
617
  }, childItems.map((child, i) => renderTreeView(child, index + i, level + 1, sync, id))));
618
618
  }
619
619
  return jsx("div", {
620
- className: 'TreeView-Item non-child ' + focusClass,
620
+ className: classNames('TreeView-Item', 'non-child', focusClass),
621
621
  style: {
622
622
  paddingLeft: 34 + 16 * level
623
623
  },
624
624
  onClick: multiple || selectBox || onChange ? e => onClickHandler(e, data) : undefined,
625
625
  key: index,
626
626
  tabIndex: "-1"
627
- }, (selectBox || multiple) && jsx("span", {
627
+ }, selectBox || multiple ? jsx("span", {
628
628
  className: 'TreeView-Item-Checkbox'
629
629
  }, jsx(Checkbox, {
630
630
  forTreeView: true,
@@ -632,7 +632,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
632
632
  value: typeof data === 'object' ? data[valueExpr] : data,
633
633
  stopPropagation: false,
634
634
  disabled: disabled
635
- })), renderContent(data, keyArr, index));
635
+ })) : null, renderContent(data, keyArr, index));
636
636
  };
637
637
  useEffect(() => {
638
638
  currentValue[unique] = {};
@@ -756,7 +756,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
756
756
  return jsx("div", {
757
757
  css: TreeViewRootCSS,
758
758
  className: classNames('DGN-UI-TreeView', disabled && 'disabled')
759
- }, showSelectedItems && jsx(InputBase, {
759
+ }, showSelectedItems && multiple ? jsx(InputBase, {
760
760
  inputRef: inputValueRef,
761
761
  viewType: 'outlined',
762
762
  readOnly: true,
@@ -774,12 +774,12 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
774
774
  name: 'Cancel',
775
775
  onClick: clearAllValue
776
776
  })
777
- }), allowSearch && jsx(InputBase, {
777
+ }) : null, allowSearch ? jsx(InputBase, {
778
778
  startIcon: 'Search',
779
779
  onChange: onChangeHandler,
780
780
  viewType: 'outlined',
781
781
  ...searchProps
782
- }), multiple && selectAll && jsx(Fragment, null, jsx("div", {
782
+ }) : null, multiple && selectAll ? jsx(Fragment, null, jsx("div", {
783
783
  className: 'TreeView-All'
784
784
  }, jsx(Checkbox, {
785
785
  forTreeView: true,
@@ -788,10 +788,10 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
788
788
  inputRef: selectAllRef,
789
789
  stopPropagation: false,
790
790
  disabled: disabled
791
- })), jsx(Divider, null)), jsx("div", {
791
+ })), jsx(Divider, null)) : null, jsx("div", {
792
792
  ref: ref,
793
- ...props,
794
- className: classNames('TreeView-Content', disabled && 'disabled', className)
793
+ className: classNames('TreeView-Content', disabled && 'disabled', className),
794
+ ...props
795
795
  }, mapParent(dataSource, id, parentID, true).map((data, index) => renderTreeView(data, index.toString(), 0, sync))));
796
796
  }, [allowSearch, autoExpandToResult, className, collapseIcon, dataSource, disabled, disabledBoldResult, disabledRelevantValue, displayExpr, expandIcon, id, multiple, multipleValueMode, onChange, parentID, renderAsyncFromLevel, renderAsyncWithLength, renderItem, searchMode, searchProps, selectAll, selectAllLabel, selectBox, showChildrenOfResult, showSelectedItems, value, valueExpr]);
797
797
  }));
@@ -802,20 +802,20 @@ const TreeViewRootCSS = css`
802
802
  box-shadow: none !important;
803
803
  .DGN-UI-Accordion-Summary {
804
804
  ${itemsCenter};
805
- min-height: 40px;
806
- padding: 0;
807
- border-radius: 0;
805
+ ${parseMinHeight(40)};
806
+ ${pd(0)};
807
+ ${borderRadius(0)};
808
808
  &.focus {
809
- background-color: ${fillFocus};
809
+ ${bgColor(fillFocus)};
810
810
  }
811
811
  .Accordion-Icon-Root {
812
812
  ${flexRow};
813
- margin-right: ${spacing([1])};
813
+ ${mgr([1])};
814
814
  }
815
815
  }
816
816
  .DGN-UI-Accordion-Details-Content {
817
- padding: 0;
818
- border-radius: 0;
817
+ ${pd(0)};
818
+ ${borderRadius(0)};
819
819
  }
820
820
  .Accordion-Icon-Root {
821
821
  ${flexRow};
@@ -834,40 +834,40 @@ const TreeViewRootCSS = css`
834
834
  ${displayBlock};
835
835
  ${positionRelative};
836
836
  .DGN-UI-Accordion {
837
- margin-bottom: 0;
837
+ ${mgb(0)};
838
838
  }
839
839
  }
840
840
  .TreeView-Item-Checkbox {
841
841
  ${displayInlineBlock};
842
842
  ${positionRelative};
843
- height: 100%;
844
- margin-right: ${spacing([2])};
843
+ ${parseHeight('100%')};
844
+ ${mgr([2])};
845
845
  }
846
846
  .TreeView-Item {
847
847
  ${flexRow};
848
848
  ${positionRelative};
849
849
  ${itemsCenter};
850
850
  ${boxBorder};
851
- min-height: 40px;
852
- text-align: left;
851
+ ${parseWidth('100%')};
852
+ ${parseMinHeight(40)};
853
+ ${textLeft};
853
854
  color: ${textMain};
854
- width: 100%;
855
855
  &.non-child {
856
856
  ${cursorPointer};
857
857
  transition: background-color 300ms ease;
858
858
  &.disabled {
859
+ ${cursorNotAllowed};
859
860
  color: ${systemDisabled};
860
- cursor: no-drop;
861
861
  }
862
862
  &:not(.disabled) {
863
863
  &:hover {
864
- background-color: ${fillHover};
864
+ ${bgColor(fillHover)};
865
865
  }
866
866
  &:focus {
867
- background-color: ${fillFocus};
867
+ ${bgColor(fillFocus)};
868
868
  }
869
869
  &:active {
870
- background-color: ${fillPressed};
870
+ ${bgColor(fillPressed)};
871
871
  }
872
872
  }
873
873
  &.DGN-Hidden {
@@ -875,7 +875,7 @@ const TreeViewRootCSS = css`
875
875
  }
876
876
  }
877
877
  &.focus {
878
- background-color: ${fillFocus};
878
+ ${bgColor(fillFocus)};
879
879
  }
880
880
  &.TreeView-Item-active .DGN-UI-Typography {
881
881
  font-weight: bold;
@@ -883,10 +883,10 @@ const TreeViewRootCSS = css`
883
883
  }
884
884
  &.expand-able {
885
885
  .TreeView-All {
886
- margin-left: ${spacing([8.5])};
886
+ ${mgl([8.5])};
887
887
  }
888
888
  .TreeView-Item.non-child {
889
- padding-left: ${spacing([8.5])};
889
+ ${pdl([8.5])};
890
890
  }
891
891
  }
892
892
  `;
@@ -918,72 +918,37 @@ TreeView.defaultProps = {
918
918
  valueExpr: ''
919
919
  };
920
920
  TreeView.propTypes = {
921
- /** expand immediate if true */
922
- expand: PropTypes.bool,
923
- /** prevent all event if true */
924
- disabled: PropTypes.bool,
925
- /** show checkbox in each item */
926
- selectBox: PropTypes.bool,
927
- /** allow select multiple item if true */
928
- multiple: PropTypes.bool,
929
- /** allow select/unselect all items on one click (just support for multiple) */
930
- selectAll: PropTypes.bool,
931
- /** display input box search if true */
921
+ /** If `true`, display input box search. */
932
922
  allowSearch: PropTypes.bool,
933
- /** display all value in a box */
934
- showSelectedItems: PropTypes.bool,
935
- /** disabled parent and children item if true (only supported for multipleValueMode is single) */
936
- disabledRelevantValue: PropTypes.bool,
937
- /** prevent display content of match values with bold style */
938
- disabledBoldResult: PropTypes.bool,
939
- /** expand TreeView to match result if true */
923
+ /** If `true`, expand TreeView to match result. */
940
924
  autoExpandToResult: PropTypes.bool,
941
- /** still show children of last result was found if true */
942
- showChildrenOfResult: PropTypes.bool,
943
- /** Used to identify the parent key */
944
- id: PropTypes.string.isRequired,
945
- /** used for mapping into a nested list */
946
- parentID: PropTypes.string.isRequired,
947
- /** class on element */
925
+ /** Class for component. */
948
926
  className: PropTypes.string,
949
- /**
950
- * field name used for text display<br/>
927
+ /** Icon display for collapse icon. */
928
+ collapseIcon: PropTypes.any,
929
+ /** The array of elements that appear in the tree list. */
930
+ dataSource: PropTypes.array,
931
+ /** If `true`, the component is disabled. */
932
+ disabled: PropTypes.bool,
933
+ /** If `true`, prevent display content of match values with bold style. */
934
+ disabledBoldResult: PropTypes.bool,
935
+ /** If `true`, disabled parent and children item (only supported for multipleValueMode is single). */
936
+ disabledRelevantValue: PropTypes.bool,
937
+ /** Field name used for text display in dropdown list.<br/>
951
938
  * Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
952
939
  * Note: don't use 'id - name', return undefined
953
940
  */
954
941
  displayExpr: PropTypes.string,
955
- /** the key to determine value to return */
956
- valueExpr: PropTypes.string,
957
- /** return value for the select multiple use case */
942
+ /** If `true`, expand immediate after render (shouldn't use this). */
943
+ expand: PropTypes.bool,
944
+ /** Icon display for expand icon. */
945
+ expandIcon: PropTypes.any,
946
+ /** If `true`, value must be an array and the treeview will support multiple selections. */
947
+ multiple: PropTypes.bool,
948
+ /** Return value for the select multiple use case. */
958
949
  multipleValueMode: PropTypes.oneOf(['single', 'multiple', 'inheritance']),
959
950
  /**
960
- * return value for the select multiple use case
961
- * * contains: "Công ty" contains "công", but not contains "cong"
962
- * * similar: "Công ty" contains "công" and "cong"
963
- */
964
- searchMode: PropTypes.oneOf(['contains', 'similar']),
965
- /** The content display for label of checkbox select all */
966
- selectAllLabel: PropTypes.string,
967
- /**
968
- * duration wait enter search content on search<br/>
969
- * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
970
- */
971
- searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
972
- /** will render asynchronously if the number of elements is greater than this number */
973
- renderAsyncWithLength: PropTypes.number,
974
- /** will render asynchronously from level equal this number */
975
- renderAsyncFromLevel: PropTypes.oneOf([2, 3, 4, 5]),
976
- /** data to show in tree list */
977
- dataSource: PropTypes.array,
978
- /** the value was selected */
979
- value: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
980
- /** function displays items by custom<br/>
981
- * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
982
- * --> such as: displayExpr={'name - role'}
983
- */
984
- renderItem: PropTypes.func,
985
- /**
986
- * on change value function<br />
951
+ * Callback fired when the value changes.<br />
987
952
  * return 2 parameters (e, data)<br />
988
953
  * * e: element (insist {value, justSelected, data})<br/>
989
954
  * &nbsp;&nbsp;&nbsp;&nbsp; + value is one or an array of selected values<br />
@@ -992,12 +957,43 @@ TreeView.propTypes = {
992
957
  * * data: array of selected values (not recommend because it's the same e.value)
993
958
  */
994
959
  onChange: PropTypes.func,
995
- /** the icon to display for expand icon */
996
- expandIcon: PropTypes.any,
997
- /** the props for InputBase */
960
+ /** Used for mapping into a nested list. */
961
+ parentID: PropTypes.string.isRequired,
962
+ /** Will render asynchronously from level equal this number. */
963
+ renderAsyncFromLevel: PropTypes.oneOf([2, 3, 4, 5]),
964
+ /** Will render asynchronously if the number of elements is greater than this number. */
965
+ renderAsyncWithLength: PropTypes.number,
966
+ /** Function displays items by custom.<br/>
967
+ * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
968
+ * --> such as: displayExpr={'name - role'}
969
+ */
970
+ renderItem: PropTypes.func,
971
+ /**
972
+ * Duration wait enter search content on search.<br/>
973
+ * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
974
+ * If `true`, used default delayOnInput.
975
+ */
976
+ searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
977
+ /** Specifies a comparison operation used to search items. */
978
+ searchMode: PropTypes.oneOf(['contains', 'similar']),
979
+ /** The props for InputBase. */
998
980
  searchProps: PropTypes.object,
999
- /** the icon to display for collapse icon */
1000
- collapseIcon: PropTypes.any,
981
+ /** If `true`, allow select/unselect all items on one click (just support for multiple). */
982
+ selectAll: PropTypes.bool,
983
+ /** The content display for label of checkbox select all */
984
+ selectAllLabel: PropTypes.string,
985
+ /** If `true`, show checkbox in each item. */
986
+ selectBox: PropTypes.bool,
987
+ /** If `true`, still show children of last result was found. */
988
+ showChildrenOfResult: PropTypes.bool,
989
+ /** If `true`, display all value in a box. */
990
+ showSelectedItems: PropTypes.bool,
991
+ /** Used to identify the parent key. */
992
+ id: PropTypes.string.isRequired,
993
+ /** The displayed value of component. */
994
+ value: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
995
+ /** The field name used for the returned result. */
996
+ valueExpr: PropTypes.string,
1001
997
  /**
1002
998
  * get ref of TreeView component, insist:<br/>
1003
999
  * {<br/>
@@ -1015,6 +1011,6 @@ TreeView.propTypes = {
1015
1011
  * &nbsp;&nbsp;&nbsp;&nbsp;get: get DOM of TreeView component<br/>
1016
1012
  * }
1017
1013
  */
1018
- ref: PropTypes.any
1014
+ ref: ref
1019
1015
  };
1020
1016
  export default TreeView;
@@ -4,14 +4,11 @@ import { css, jsx } from '@emotion/core';
4
4
  import { Popover } from "./..";
5
5
  import PropTypes from 'prop-types';
6
6
  import { forwardRef, Fragment, memo, useImperativeHandle, useMemo, useRef, useState } from 'react';
7
- import { breakAll, breakWord, cursorPointer, displayBlock, displayInlineBlock, italic, overflowHidden, parseHeight, parseMaxWidth, pd, positionRelative, textCapitalize, textCenter, textColor, textLineThrough, textLowercase, textunderline, textUppercase, whiteSpaceBreakSpaces } from "../../styles/general";
7
+ import { breakAll, breakWord, cursorPointer, displayBlock, displayInlineBlock, italic, overflowHidden, parseHeight, parseMaxWidth, parseMinWidth, pd, positionRelative, textCapitalize, textCenter, textColor, textLineThrough, textLowercase, textUnderline, textUppercase, whiteSpaceBreakSpaces } from "../../styles/general";
8
8
  import { useTheme, useTypography as typography } from "../../theme";
9
9
  import { classNames, renderHTML } from "../../utils";
10
10
  const {
11
11
  colors: {
12
- system: {
13
- rest: systemRest
14
- },
15
12
  text: {
16
13
  main: textMain
17
14
  },
@@ -20,8 +17,8 @@ const {
20
17
  }
21
18
  }
22
19
  } = useTheme();
23
- const colorMap = new Map([['default', textMain], ['secondary', systemRest]]);
24
- const formatMap = new Map([['capitalize', textCapitalize], ['uppercase', textUppercase], ['lowercase', textLowercase], ['italic', italic], ['line-through', textLineThrough], ['underline', textunderline]]);
20
+ const colorMap = new Map([['default', textMain]]);
21
+ const formatMap = new Map([['capitalize', textCapitalize], ['uppercase', textUppercase], ['lowercase', textLowercase], ['italic', italic], ['line-through', textLineThrough], ['underline', textUnderline]]);
25
22
  const isTextClamped = elm => (elm === null || elm === void 0 ? void 0 : elm.scrollHeight) > (elm === null || elm === void 0 ? void 0 : elm.clientHeight);
26
23
  const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
27
24
  action = {},
@@ -76,6 +73,7 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
76
73
  const classes = (inTooltip = false) => classNames('DGN-UI-Typography', center && 'DGN-Typography-center', fullWidth && 'DGN-Typography-fullWidth', `DGN-Typography-${type}`, uppercase && `DGN-Typography-Uppercase`, capitalize && 'DGN-Typography-Capitalize', !inTooltip && lineClamp && 'DGN-Typography-Clamp', className);
77
74
  const content = Array.isArray(children) && !children.some(node => node && String(node.$$typeof) === 'Symbol(react.element)') ? children.join('') : children;
78
75
  const renderTooltip = hoverTooltip ? jsx(Popover, {
76
+ css: [parseMinWidth(300)],
79
77
  open: openTooltip,
80
78
  pressESCToClose: false,
81
79
  fullScreen: false,
package/global/index.js CHANGED
@@ -11,8 +11,8 @@ const globalObject = {
11
11
  noDataText: 'Không có dữ liệu',
12
12
  notify: 'Thông báo',
13
13
  ok: 'Đồng ý',
14
- showLess: 'Thu gọn',
15
- showMore: 'Chi tiết',
14
+ showLess: 'Rút gọn',
15
+ showMore: 'Xem thêm',
16
16
  yes: 'Có',
17
17
  warning: 'Cảnh Báo',
18
18
  // attachment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.90",
3
+ "version": "1.3.91",
4
4
  "description": "The DigiNet core ui",
5
5
  "homepage": "https://diginet.com.vn",
6
6
  "main": "index.js",
package/readme.md CHANGED
@@ -38,6 +38,16 @@ npm test
38
38
  ```
39
39
 
40
40
  ## Changelog
41
+ ## 1.3.91
42
+ - \[Changed\]: TreeView – Optimize code
43
+ - \[Changed\]: Popup – Add defaultProps description
44
+ - \[Changed\]: Grid – Add sx prop handle responsive css display
45
+ - \[Changed\]: ButtonMore – Export component ButtonMore
46
+ - \[Changed\]: DateRangePicker – Add description for prop value
47
+ - \[Fixed\]: Avatar – Fix bug not clear avatar when src null
48
+ - \[Fixed\]: Typography – Add min-width to popover hover tooltip
49
+ - \[Fixed\]: DatePicker – Fix disabled button previous month in navigator
50
+
41
51
  ## 1.3.90
42
52
  - \[Added\]: Breadcrumb – Add component Breadcrumb
43
53
  - \[Added\]: Icon – Question, Pause, Cake, ChatAnswer
package/styles/general.js CHANGED
@@ -95,6 +95,9 @@ const cursorDefault = css`
95
95
  const cursorInherit = css`
96
96
  cursor: inherit;
97
97
  `;
98
+ const cursorInitial = css`
99
+ cursor: initial;
100
+ `;
98
101
  const cursorMove = css`
99
102
  cursor: move;
100
103
  `;
@@ -410,7 +413,7 @@ const textLowercase = css`
410
413
  const textRight = css`
411
414
  text-align: right;
412
415
  `;
413
- const textunderline = css`
416
+ const textUnderline = css`
414
417
  text-decoration: underline;
415
418
  `;
416
419
  const textUppercase = css`
@@ -442,4 +445,4 @@ const whiteSpacePreWrap = css`
442
445
  const z = vl => css`
443
446
  z-index: ${zIndex(vl)};
444
447
  `;
445
- export { bgColor, bgCurrent, bgTransparent, border, borderBottom, borderBottomColor, borderColor, borderNone, borderRadius, borderRadius100, borderRadius4px, borderRadius50, bottom, boxBorder, boxContent, breakAll, breakWord, cursorDefault, cursorInherit, cursorMove, cursorNoDrop, cursorNotAllowed, cursorPointer, cursorText, displayBlock, displayFlex, displayInlineBlock, displayInlineFlex, displayNone, fill, flexCol, flexColReverse, flexNowrap, flexRow, flexRowReverse, flexShrink, flexShrink0, flexWrap, flexWrapReverse, floatLeft, floatNone, floatRight, gap, gapX, gapY, inset, insetX, insetY, invisible, italic, itemsCenter, itemsEnd, itemsStart, justifyAround, justifyBetween, justifyCenter, justifyEnd, justifyEvenly, justifyStart, left, mg, mgb, mgl, mgr, mgt, mgx, mgy, noBorder, noBoxShadow, noMargin, noPadding, objectContain, objectCover, objectFill, objectNone, order, outlineNone, overflowAuto, overflowHidden, parseHeight, parseMaxHeight, parseMaxWidth, parseMaxWidthHeight, parseMinHeight, parseMinWidth, parseMinWidthHeight, parseWidth, parseWidthHeight, pd, pdb, pdl, pdr, pdt, pdx, pdy, pointerEventsAuto, pointerEventsInherit, pointerEventsInitial, pointerEventsNone, positionAbsolute, positionFixed, positionRelative, positionSticky, right, scale, scaleX, scaleY, selfCenter, selfEnd, selfStart, shadowNone, textCapitalize, textCenter, textColor, textCurrent, textEllipsis, textLeft, textLineThrough, textLowercase, textRight, textunderline, textUppercase, top, truncate, userSelectNone, visible, whiteSpaceBreakSpaces, whiteSpaceNoWrap, whiteSpacePreWrap, z };
448
+ export { bgColor, bgCurrent, bgTransparent, border, borderBottom, borderBottomColor, borderColor, borderNone, borderRadius, borderRadius100, borderRadius4px, borderRadius50, bottom, boxBorder, boxContent, breakAll, breakWord, cursorDefault, cursorInherit, cursorInitial, cursorMove, cursorNoDrop, cursorNotAllowed, cursorPointer, cursorText, displayBlock, displayFlex, displayInlineBlock, displayInlineFlex, displayNone, fill, flexCol, flexColReverse, flexNowrap, flexRow, flexRowReverse, flexShrink, flexShrink0, flexWrap, flexWrapReverse, floatLeft, floatNone, floatRight, gap, gapX, gapY, inset, insetX, insetY, invisible, italic, itemsCenter, itemsEnd, itemsStart, justifyAround, justifyBetween, justifyCenter, justifyEnd, justifyEvenly, justifyStart, left, mg, mgb, mgl, mgr, mgt, mgx, mgy, noBorder, noBoxShadow, noMargin, noPadding, objectContain, objectCover, objectFill, objectNone, order, outlineNone, overflowAuto, overflowHidden, parseHeight, parseMaxHeight, parseMaxWidth, parseMaxWidthHeight, parseMinHeight, parseMinWidth, parseMinWidthHeight, parseWidth, parseWidthHeight, pd, pdb, pdl, pdr, pdt, pdx, pdy, pointerEventsAuto, pointerEventsInherit, pointerEventsInitial, pointerEventsNone, positionAbsolute, positionFixed, positionRelative, positionSticky, right, scale, scaleX, scaleY, selfCenter, selfEnd, selfStart, shadowNone, textCapitalize, textCenter, textColor, textCurrent, textEllipsis, textLeft, textLineThrough, textLowercase, textRight, textUnderline, textUppercase, top, truncate, userSelectNone, visible, whiteSpaceBreakSpaces, whiteSpaceNoWrap, whiteSpacePreWrap, z };
@@ -0,0 +1,23 @@
1
+ import { css } from '@emotion/core';
2
+ import { handleBreakpoints } from "../../utils";
3
+ const cssKeyMap = new Map([['display', 'display']]);
4
+ const sx = prop => {
5
+ if (typeof prop !== 'object' || Array.isArray(prop) || prop === null) return null;
6
+ let sxStyleCSS = '';
7
+ Object.keys(prop).forEach(key => {
8
+ const cssKey = cssKeyMap.get(key);
9
+ if (!cssKey) return null;
10
+ sxStyleCSS += handleBreakpoints(prop[key], propValue => {
11
+ if (propValue) {
12
+ return `
13
+ ${cssKey}: ${propValue};
14
+ `;
15
+ }
16
+ return '';
17
+ });
18
+ });
19
+ return css`
20
+ ${sxStyleCSS}
21
+ `;
22
+ };
23
+ export default sx;
package/styles/utils.js CHANGED
@@ -1,31 +1,31 @@
1
1
  import { color as colors } from "./colors";
2
2
 
3
- /**
4
- * Parse css value
5
- *
6
- * @param {string | number} vl
7
- * @returns {string | number}
3
+ /**
4
+ * Parse css value
5
+ *
6
+ * @param {string | number} vl
7
+ * @returns {string | number}
8
8
  */
9
9
  export const parseCSSValue = vl => {
10
10
  return isNaN(vl) ? vl : vl + 'px';
11
11
  };
12
12
 
13
- /**
14
- * Parse to pixel
15
- *
16
- * @param {number} vl
17
- * @returns {string}
13
+ /**
14
+ * Parse to pixel
15
+ *
16
+ * @param {number} vl
17
+ * @returns {string}
18
18
  */
19
19
  export const parseToPixel = vl => {
20
20
  if (!vl) return '1px';
21
21
  return typeof vl === 'string' ? vl : `${vl}px`;
22
22
  };
23
23
 
24
- /**
25
- * Get color from CORE colors
26
- *
27
- * @param {string} cl
28
- * @returns {string}
24
+ /**
25
+ * Get color from CORE colors
26
+ *
27
+ * @param {string} cl
28
+ * @returns {string}
29
29
  */
30
30
  export const getColor = cl => {
31
31
  if (typeof cl !== 'string') return;
package/utils/index.js CHANGED
@@ -19,6 +19,7 @@ export { default as SbTemplate } from "./sb-template";
19
19
  export { default as updatePosition } from "./updatePosition";
20
20
  export { default as useDelayUnmount } from "./useDelayUnmount";
21
21
  export { default as useInput } from "./useInput";
22
+ export { default as useIntersection } from "./intersectionObserver";
22
23
  export { default as useMediaQuery } from "./useMediaQuery";
23
24
  export { default as useOnClickOutside } from "./useOnClickOutside";
24
25
  export { default as usePortal } from "./usePortal";
@@ -22,7 +22,7 @@ const getIntersectionObserver = () => {
22
22
  }
23
23
  return observer;
24
24
  };
25
- export const useIntersection = (elem, callback) => {
25
+ const useIntersection = (elem, callback) => {
26
26
  useEffect(() => {
27
27
  let target = elem.current;
28
28
  let observer = getIntersectionObserver();
@@ -33,4 +33,5 @@ export const useIntersection = (elem, callback) => {
33
33
  observer.unobserve(target);
34
34
  };
35
35
  }, []);
36
- };
36
+ };
37
+ export default useIntersection;