@elastic/eui 94.0.0 → 94.1.0

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.
Files changed (33) hide show
  1. package/es/components/basic_table/basic_table.js +6 -2
  2. package/es/components/basic_table/collapsed_item_actions.js +11 -20
  3. package/es/components/basic_table/default_item_action.js +9 -16
  4. package/es/components/basic_table/in_memory_table.js +6 -2
  5. package/es/components/table/table_cells_shared.styles.js +7 -2
  6. package/es/components/table/table_header_cell.js +31 -33
  7. package/eui.d.ts +5 -3
  8. package/i18ntokens.json +14 -14
  9. package/lib/components/basic_table/basic_table.js +6 -2
  10. package/lib/components/basic_table/collapsed_item_actions.js +11 -20
  11. package/lib/components/basic_table/default_item_action.js +12 -17
  12. package/lib/components/basic_table/in_memory_table.js +6 -2
  13. package/lib/components/table/table_cells_shared.styles.js +7 -2
  14. package/lib/components/table/table_header_cell.js +31 -33
  15. package/optimize/es/components/basic_table/collapsed_item_actions.js +11 -20
  16. package/optimize/es/components/basic_table/default_item_action.js +9 -16
  17. package/optimize/es/components/table/table_cells_shared.styles.js +7 -2
  18. package/optimize/es/components/table/table_header_cell.js +31 -33
  19. package/optimize/lib/components/basic_table/collapsed_item_actions.js +11 -20
  20. package/optimize/lib/components/basic_table/default_item_action.js +12 -17
  21. package/optimize/lib/components/table/table_cells_shared.styles.js +7 -2
  22. package/optimize/lib/components/table/table_header_cell.js +31 -33
  23. package/package.json +2 -2
  24. package/test-env/components/basic_table/basic_table.js +6 -2
  25. package/test-env/components/basic_table/collapsed_item_actions.js +11 -20
  26. package/test-env/components/basic_table/default_item_action.js +12 -17
  27. package/test-env/components/basic_table/in_memory_table.js +6 -2
  28. package/test-env/components/table/table_cells_shared.styles.js +7 -2
  29. package/test-env/components/table/table_header_cell.js +31 -33
  30. package/src/components/date_picker/react-datepicker/LICENSE +0 -21
  31. package/src/components/date_picker/react-datepicker/README.md +0 -168
  32. package/src/services/theme/README.md +0 -153
  33. package/src/test/README.md +0 -44
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.CollapsedItemActions = void 0;
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _react = _interopRequireWildcard(require("react"));
11
- var _predicate = require("../../services/predicate");
12
11
  var _context_menu = require("../context_menu");
13
12
  var _popover = require("../popover");
14
13
  var _button = require("../button");
@@ -36,9 +35,8 @@ var CollapsedItemActions = function CollapsedItemActions(_ref) {
36
35
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
36
  popoverOpen = _useState2[0],
38
37
  setPopoverOpen = _useState2[1];
39
- var onClickItem = (0, _react.useCallback)(function (onClickAction) {
40
- setPopoverOpen(false);
41
- onClickAction === null || onClickAction === void 0 ? void 0 : onClickAction();
38
+ var closePopover = (0, _react.useCallback)(function () {
39
+ return setPopoverOpen(false);
42
40
  }, []);
43
41
  var controls = (0, _react.useMemo)(function () {
44
42
  return actions.reduce(function (controls, action, index) {
@@ -57,16 +55,10 @@ var CollapsedItemActions = function CollapsedItemActions(_ref) {
57
55
  key: index,
58
56
  className: "euiBasicTable__collapsedCustomAction"
59
57
  }, (0, _react2.jsx)("span", {
60
- onClick: function onClick() {
61
- return onClickItem();
62
- }
58
+ onClick: closePopover
63
59
  }, actionControl)));
64
60
  } else {
65
- var buttonIcon = action.icon;
66
- var icon;
67
- if (buttonIcon) {
68
- icon = (0, _predicate.isString)(buttonIcon) ? buttonIcon : buttonIcon(item);
69
- }
61
+ var icon = action.icon ? (0, _action_types.callWithItemIfFunction)(item)(action.icon) : undefined;
70
62
  var buttonContent = (0, _action_types.callWithItemIfFunction)(item)(action.name);
71
63
  var toolTipContent = (0, _action_types.callWithItemIfFunction)(item)(action.description);
72
64
  var href = (0, _action_types.callWithItemIfFunction)(item)(action.href);
@@ -81,10 +73,11 @@ var CollapsedItemActions = function CollapsedItemActions(_ref) {
81
73
  target: target,
82
74
  icon: icon,
83
75
  "data-test-subj": dataTestSubj,
84
- onClick: function onClick() {
85
- return onClickItem(_onClick ? function () {
86
- return _onClick(item);
87
- } : undefined);
76
+ onClick: function onClick(event) {
77
+ event.persist();
78
+ _onClick === null || _onClick === void 0 ? void 0 : _onClick(item, event);
79
+ // Allow consumer events to prevent the popover from closing if necessary
80
+ if (!event.isPropagationStopped()) closePopover();
88
81
  },
89
82
  toolTipContent: toolTipContent,
90
83
  toolTipProps: {
@@ -94,7 +87,7 @@ var CollapsedItemActions = function CollapsedItemActions(_ref) {
94
87
  }
95
88
  return controls;
96
89
  }, []);
97
- }, [actions, actionsDisabled, item, onClickItem]);
90
+ }, [actions, actionsDisabled, item, closePopover]);
98
91
  var popoverButton = (0, _react2.jsx)(_i18n.EuiI18n, {
99
92
  tokens: ['euiCollapsedItemActions.allActions', 'euiCollapsedItemActions.allActionsDisabled'],
100
93
  defaults: ['All actions', 'Individual item actions are disabled when rows are being selected.']
@@ -131,9 +124,7 @@ var CollapsedItemActions = function CollapsedItemActions(_ref) {
131
124
  id: "".concat(itemId, "-actions"),
132
125
  isOpen: popoverOpen,
133
126
  button: withTooltip || popoverButton,
134
- closePopover: function closePopover() {
135
- return setPopoverOpen(false);
136
- },
127
+ closePopover: closePopover,
137
128
  panelPaddingSize: "none",
138
129
  anchorPosition: "leftCenter"
139
130
  }, (0, _react2.jsx)(_context_menu.EuiContextMenuPanel, {
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.DefaultItemAction = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _predicate = require("../../services/predicate");
8
+ var _react = _interopRequireWildcard(require("react"));
10
9
  var _button = require("../button");
11
10
  var _tool_tip = require("../tool_tip");
12
11
  var _accessibility = require("../../services/accessibility");
13
12
  var _accessibility2 = require("../accessibility");
14
13
  var _action_types = require("./action_types");
15
14
  var _react2 = require("@emotion/react");
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
17
  /*
17
18
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
18
19
  * or more contributor license agreements. Licensed under the Elastic License
@@ -29,26 +30,20 @@ var DefaultItemAction = function DefaultItemAction(_ref) {
29
30
  if (!action.onClick && !action.href) {
30
31
  throw new Error("Cannot render item action [".concat(action.name, "]. Missing required 'onClick' callback\n or 'href' string. If you want to provide a custom action control, make sure to define the 'render' callback"));
31
32
  }
32
- var onClick = action.onClick ? function () {
33
- return action.onClick(item);
34
- } : undefined;
35
- var buttonColor = action.color;
36
- var color = 'primary';
37
- if (buttonColor) {
38
- color = (0, _predicate.isString)(buttonColor) ? buttonColor : buttonColor(item);
39
- }
40
- var buttonIcon = action.icon;
41
- var icon;
42
- if (buttonIcon) {
43
- icon = (0, _predicate.isString)(buttonIcon) ? buttonIcon : buttonIcon(item);
44
- }
45
- var button;
33
+ var onClick = (0, _react.useCallback)(function (event) {
34
+ if (!action.onClick) return;
35
+ event.persist(); // TODO: Remove once React 16 support is dropped
36
+ action.onClick(item, event);
37
+ }, [action.onClick, item]);
38
+ var color = action.color ? (0, _action_types.callWithItemIfFunction)(item)(action.color) : 'primary';
39
+ var icon = action.icon ? (0, _action_types.callWithItemIfFunction)(item)(action.icon) : undefined;
46
40
  var actionContent = (0, _action_types.callWithItemIfFunction)(item)(action.name);
47
41
  var tooltipContent = (0, _action_types.callWithItemIfFunction)(item)(action.description);
48
42
  var href = (0, _action_types.callWithItemIfFunction)(item)(action.href);
49
43
  var dataTestSubj = (0, _action_types.callWithItemIfFunction)(item)(action['data-test-subj']);
50
44
  var ariaLabelId = (0, _accessibility.useGeneratedHtmlId)();
51
45
  var ariaLabelledBy;
46
+ var button;
52
47
  if (action.type === 'icon') {
53
48
  if (!icon) {
54
49
  throw new Error("Cannot render item action [".concat(action.name, "]. It is configured to render as an icon but no\n icon is provided. Make sure to set the 'icon' property of the action"));
@@ -679,10 +679,14 @@ EuiInMemoryTable.propTypes = {
679
679
  */
680
680
  description: _propTypes.default.oneOfType([_propTypes.default.string.isRequired, _propTypes.default.func.isRequired]).isRequired,
681
681
  /**
682
- * A handler function to execute the action
682
+ * A handler function to execute the action. Passes back the current row
683
+ * item as the first argument, and the originating React click event
684
+ * as a second argument.
683
685
  */
684
686
  /**
685
- * A handler function to execute the action
687
+ * A handler function to execute the action. Passes back the current row
688
+ * item as the first argument, and the originating React click event
689
+ * as a second argument.
686
690
  */
687
691
  onClick: _propTypes.default.func,
688
692
  href: _propTypes.default.oneOfType([_propTypes.default.string.isRequired, _propTypes.default.func.isRequired]),
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.euiTableHeaderFooterCellStyles = exports.euiTableCellCheckboxStyles = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = require("@emotion/react");
10
+ var _services = require("../../services");
10
11
  var _global_styling = require("../../global_styling");
11
12
  var _table = require("./table.styles");
12
13
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -18,7 +19,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
18
19
  * Side Public License, v 1.
19
20
  */
20
21
  var euiTableHeaderFooterCellStyles = function euiTableHeaderFooterCellStyles(euiThemeContext) {
21
- var euiTheme = euiThemeContext.euiTheme;
22
+ var euiTheme = euiThemeContext.euiTheme,
23
+ colorMode = euiThemeContext.colorMode;
22
24
 
23
25
  // euiFontSize returns an object, so we keep object notation here to merge into css``
24
26
  var sharedStyles = _objectSpread(_objectSpread({}, (0, _global_styling.euiFontSize)(euiThemeContext, 'xs')), {}, {
@@ -29,7 +31,10 @@ var euiTableHeaderFooterCellStyles = function euiTableHeaderFooterCellStyles(eui
29
31
  return {
30
32
  euiTableHeaderCell: /*#__PURE__*/(0, _react.css)(sharedStyles, ";;label:euiTableHeaderCell;"),
31
33
  euiTableHeaderCell__content: /*#__PURE__*/(0, _react.css)("gap:", euiTheme.size.xs, ";;label:euiTableHeaderCell__content;"),
32
- euiTableHeaderCell__button: /*#__PURE__*/(0, _react.css)((0, _global_styling.logicalCSS)('width', '100%'), " font-weight:inherit;&:hover,&:focus{color:", euiTheme.colors.primaryText, ";text-decoration:underline;};label:euiTableHeaderCell__button;"),
34
+ euiTableHeaderCell__button: /*#__PURE__*/(0, _react.css)((0, _global_styling.logicalCSS)('width', '100%'), " font-weight:inherit;line-height:inherit;.euiTableSortIcon--sortable{color:", (0, _services.makeHighContrastColor)(
35
+ // Tint it arbitrarily high, the contrast util will take care of lowering back down to WCAG
36
+ (0, _services.tintOrShade)(euiTheme.colors.subduedText, 0.9, colorMode), 3 // 3:1 ratio from https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html
37
+ )(euiTheme.colors.emptyShade), ";}&:hover,&:focus{color:", euiTheme.colors.primaryText, ";text-decoration:underline;.euiTableSortIcon--sortable{color:", euiTheme.colors.primaryText, ";}};label:euiTableHeaderCell__button;"),
33
38
  euiTableFooterCell: /*#__PURE__*/(0, _react.css)(sharedStyles, " background-color:", euiTheme.colors.lightestShade, ";;label:euiTableFooterCell;")
34
39
  };
35
40
  };
@@ -33,9 +33,9 @@ var CellContents = function CellContents(_ref) {
33
33
  align = _ref.align,
34
34
  description = _ref.description,
35
35
  children = _ref.children,
36
+ canSort = _ref.canSort,
36
37
  isSorted = _ref.isSorted,
37
- isSortAscending = _ref.isSortAscending,
38
- showSortMsg = _ref.showSortMsg;
38
+ isSortAscending = _ref.isSortAscending;
39
39
  return (0, _react2.jsx)(_table_cell_content.EuiTableCellContent, {
40
40
  className: className,
41
41
  align: align,
@@ -56,11 +56,16 @@ var CellContents = function CellContents(_ref) {
56
56
  className: "eui-textTruncate"
57
57
  }, children);
58
58
  });
59
- }), description && (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("span", null, description)), showSortMsg && isSorted && (0, _react2.jsx)(_icon.EuiIcon, {
59
+ }), description && (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("span", null, description)), isSorted ? (0, _react2.jsx)(_icon.EuiIcon, {
60
60
  className: "euiTableSortIcon",
61
61
  type: isSortAscending ? 'sortUp' : 'sortDown',
62
62
  size: "m"
63
- }));
63
+ }) : canSort ? (0, _react2.jsx)(_icon.EuiIcon, {
64
+ className: "euiTableSortIcon euiTableSortIcon--sortable",
65
+ type: "sortable",
66
+ size: "m",
67
+ color: "subdued" // Tinted a bit further via CSS
68
+ }) : null);
64
69
  };
65
70
  var EuiTableHeaderCell = function EuiTableHeaderCell(_ref2) {
66
71
  var children = _ref2.children,
@@ -87,45 +92,38 @@ var EuiTableHeaderCell = function EuiTableHeaderCell(_ref2) {
87
92
  var CellComponent = children ? 'th' : 'td';
88
93
  var cellScope = CellComponent === 'th' ? scope !== null && scope !== void 0 ? scope : 'col' : undefined; // `scope` is only valid on `th` elements
89
94
 
90
- var cellContents = (0, _react2.jsx)(CellContents, {
95
+ var canSort = !!(onSort && !readOnly);
96
+ var ariaSortValue;
97
+ if (isSorted) {
98
+ ariaSortValue = isSortAscending ? 'ascending' : 'descending';
99
+ } else if (canSort) {
100
+ ariaSortValue = 'none';
101
+ }
102
+ var cellContentsProps = {
91
103
  css: styles.euiTableHeaderCell__content,
92
104
  align: align,
93
105
  description: description,
94
- showSortMsg: true,
106
+ canSort: canSort,
95
107
  isSorted: isSorted,
96
- isSortAscending: isSortAscending
97
- }, children);
98
- if (onSort || isSorted) {
99
- var buttonClasses = (0, _classnames.default)('euiTableHeaderButton', {
100
- 'euiTableHeaderButton-isSorted': isSorted
101
- });
102
- var ariaSortValue = 'none';
103
- if (isSorted) {
104
- ariaSortValue = isSortAscending ? 'ascending' : 'descending';
105
- }
106
- return (0, _react2.jsx)(CellComponent, (0, _extends2.default)({
107
- css: styles.euiTableHeaderCell,
108
- className: classes,
109
- scope: cellScope,
110
- role: "columnheader",
111
- "aria-sort": ariaSortValue,
112
- "aria-live": "polite",
113
- style: inlineStyles
114
- }, rest), onSort && !readOnly ? (0, _react2.jsx)("button", {
115
- type: "button",
116
- css: styles.euiTableHeaderCell__button,
117
- className: buttonClasses,
118
- onClick: onSort,
119
- "data-test-subj": "tableHeaderSortButton"
120
- }, cellContents) : cellContents);
121
- }
108
+ isSortAscending: isSortAscending,
109
+ children: children
110
+ };
122
111
  return (0, _react2.jsx)(CellComponent, (0, _extends2.default)({
123
112
  css: styles.euiTableHeaderCell,
124
113
  className: classes,
125
114
  scope: cellScope,
126
115
  role: "columnheader",
116
+ "aria-sort": ariaSortValue,
127
117
  style: inlineStyles
128
- }, rest), cellContents);
118
+ }, rest), canSort ? (0, _react2.jsx)("button", {
119
+ type: "button",
120
+ css: styles.euiTableHeaderCell__button,
121
+ className: (0, _classnames.default)('euiTableHeaderButton', {
122
+ 'euiTableHeaderButton-isSorted': isSorted
123
+ }),
124
+ onClick: onSort,
125
+ "data-test-subj": "tableHeaderSortButton"
126
+ }, (0, _react2.jsx)(CellContents, cellContentsProps)) : (0, _react2.jsx)(CellContents, cellContentsProps));
129
127
  };
130
128
  exports.EuiTableHeaderCell = EuiTableHeaderCell;
131
129
  EuiTableHeaderCell.propTypes = {
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 HackerOne Inc and individual contributors
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.
@@ -1,168 +0,0 @@
1
- _Forked by @elastic/eui from Hacker0x01/react-datepicker for accessibility and consolidation of services._
2
-
3
- Decision to not use a more traditional "vendor" directory approach includes redundant services, unnecessary dependencies, and a separate build pipeline. Most notably, `react-datepicker` included third-party popover and focus trap service and components that do not align with EUI interaction standards and were replaced, at parity, with EUI components.
4
-
5
- Other modifications:
6
-
7
- * Changed to `.js` naming to conform to EUI build processes
8
- * Removed files related to repository management and publishing
9
- * Adjusted `babel.rc` and `package.json` naming to avoid babel configuration conflicts
10
-
11
- ___
12
- # React Date Picker
13
-
14
- [![npm version](https://badge.fury.io/js/react-datepicker.svg)](https://badge.fury.io/js/react-datepicker)
15
- [![Build Status](https://travis-ci.org/Hacker0x01/react-datepicker.svg?branch=master)](https://travis-ci.org/Hacker0x01/react-datepicker)
16
- [![Dependency Status](https://david-dm.org/Hacker0x01/react-datepicker.svg)](https://david-dm.org/Hacker0x01/react-datepicker)
17
- [![codecov](https://codecov.io/gh/Hacker0x01/react-datepicker/branch/master/graph/badge.svg)](https://codecov.io/gh/Hacker0x01/react-datepicker)
18
- [![Downloads](http://img.shields.io/npm/dm/react-datepicker.svg)](https://npmjs.org/package/react-datepicker)
19
- [![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/Hacker0x01/react-datepicker.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Hacker0x01/react-datepicker/context:javascript)
20
- [![Total Alerts](https://img.shields.io/lgtm/alerts/g/Hacker0x01/react-datepicker.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Hacker0x01/react-datepicker/alerts)
21
-
22
- A simple and reusable Datepicker component for React ([Demo](https://reactdatepicker.com/))
23
-
24
- ![](https://cloud.githubusercontent.com/assets/1412392/5339491/c40de124-7ee1-11e4-9f07-9276e2545f27.png)
25
-
26
- ## Installation
27
-
28
- The package can be installed via NPM:
29
-
30
- ```
31
- npm install react-datepicker --save
32
- ```
33
-
34
- You’ll need to install React, PropTypes, and Moment.js separately since those dependencies aren’t included in the package. Below is a simple example of how to use the Datepicker in a React view. You will also need to require the CSS file from this package (or provide your own). The example below shows how to include the CSS from this package if your build system supports requiring CSS files (Webpack is one that does).
35
-
36
- ```js
37
- import React from "react";
38
- import DatePicker from "react-datepicker";
39
- import moment from "moment";
40
-
41
- import "react-datepicker/dist/react-datepicker.css";
42
-
43
- // CSS Modules, react-datepicker-cssmodules.css
44
- // import 'react-datepicker/dist/react-datepicker-cssmodules.css';
45
-
46
- class Example extends React.Component {
47
- constructor(props) {
48
- super(props);
49
- this.state = {
50
- startDate: moment()
51
- };
52
- this.handleChange = this.handleChange.bind(this);
53
- }
54
-
55
- handleChange(date) {
56
- this.setState({
57
- startDate: date
58
- });
59
- }
60
-
61
- render() {
62
- return (
63
- <DatePicker
64
- selected={this.state.startDate}
65
- onChange={this.handleChange}
66
- />
67
- );
68
- }
69
- }
70
- ```
71
-
72
- ## Configuration
73
-
74
- The most basic use of the DatePicker can be described with:
75
-
76
- ```js
77
- <DatePicker selected={this.state.date} onChange={this.handleChange} />
78
- ```
79
-
80
- You can use `onSelect` event handler which fires each time some calendar date has been selected
81
-
82
- ```js
83
- <DatePicker
84
- selected={this.state.date}
85
- onSelect={this.handleSelect} //when day is clicked
86
- onChange={this.handleChange} //only when value has changed
87
- />
88
- ```
89
-
90
- `onClickOutside` handler may be useful to close datepicker in `inline` mode
91
-
92
- See [here](https://github.com/Hacker0x01/react-datepicker/blob/master/docs/datepicker.md) for a full list of props that may be passed to the component. Examples are given on the [main website](https://hacker0x01.github.io/react-datepicker).
93
-
94
- ### Time picker
95
-
96
- You can also include a time picker by adding the showTimeSelect prop
97
-
98
- ```js
99
- <DatePicker
100
- selected={this.state.date}
101
- onChange={this.handleChange}
102
- showTimeSelect
103
- dateFormat="LLL"
104
- />
105
- ```
106
-
107
- Times will be displayed at 30-minute intervals by default (default configurable via timeInterval prop)
108
-
109
- More examples of how to use the time picker are given on the [main website](https://hacker0x01.github.io/react-datepicker)
110
-
111
- ### Localization
112
-
113
- The date picker relies on [moment.js internationalization](http://momentjs.com/docs/#/i18n/) to localize its display components. By default, the date picker will use the locale globally set in moment, which is English. Locales can be changed in the following ways:
114
-
115
- * **Globally** by calling `moment.locale(lang)`
116
- * **Picker-specific** by providing the `locale` prop
117
-
118
- Locales can be further configured in moment with various [customization options](http://momentjs.com/docs/#/customization/).
119
-
120
- _As of version 0.23, the `weekdays` and `weekStart` DatePicker props have been removed. Instead, they can be configured with the `weekdaysMin` and `week.dow` moment locale customization options._
121
-
122
- ## Compatibility
123
-
124
- ### React
125
-
126
- We're always trying to stay compatible with the latest version of React. We can't support all older versions of React.
127
-
128
- Latest compatible versions:
129
-
130
- * React 15.5 or newer: All above React-datepicker v.0.40.0
131
- * React 15.4.1: needs React-datepicker v0.40.0, newer won't work (due to react-onclickoutside dependencies)
132
- * React 0.14 or newer: All above React-datepicker v0.13.0
133
- * React 0.13: React-datepicker v0.13.0
134
- * pre React 0.13: React-datepicker v0.6.2
135
-
136
- ### Browser Support
137
-
138
- The date picker is compatible with the latest versions of Chrome, Firefox, and IE10+.
139
-
140
- Unfortunately, it is difficult to support legacy browsers while maintaining our ability to develop new features in the future. For IE9 support, it is known that the [classlist polyfill](https://www.npmjs.com/package/classlist-polyfill) is needed, but this may change or break at any point in the future.
141
-
142
- ## Local Development
143
-
144
- The `master` branch contains the latest version of the Datepicker component. To start your example app, you can run `yarn start`. This starts a simple webserver on http://localhost:8080.
145
-
146
- You can run `yarn test` to execute the test suite and linters. To help you develop the component we’ve set up some tests that cover the basic functionality (can be found in `/tests`). Even though we’re big fans of testing, this only covers a small piece of the component. We highly recommend you add tests when you’re adding new functionality.
147
-
148
- ### The examples
149
-
150
- The examples are hosted within the docs folder and are ran in the simple app that loads the Datepicker. To extend the examples with a new example, you can simply duplicate one of the existing examples and change the unique properties of your example.
151
-
152
- ## Accessibility
153
-
154
- ### Keyboard support
155
-
156
- * _Left_: Move to the previous day.
157
- * _Right_: Move to the next day.
158
- * _Up_: Move to the previous week.
159
- * _Down_: Move to the next week.
160
- * _PgUp_: Move to the previous month.
161
- * _PgDn_: Move to the next month.
162
- * _Home_: Move to the previous year.
163
- * _End_: Move to the next year.
164
- * _Enter/Esc/Tab_: close the calendar. (Enter & Esc calls preventDefault)
165
-
166
- ## License
167
-
168
- Copyright (c) 2018 HackerOne Inc. and individual contributors. Licensed under MIT license, see [LICENSE](LICENSE) for the full license.
@@ -1,153 +0,0 @@
1
- # JavaScript-based theming in EUI
2
-
3
- The style system to replace Sass and Sass-based design tokens in EUI.
4
-
5
- * Theme construction via a Proxy-based system with cascading and computed values
6
- * Proxy-based: allows for the theme system to reference its own values (for reuse or for computational manipulation)
7
- * Cascading: conceptually similar to Sass, where variable location and order are important
8
- * Extendable: allows for appending style variables to the EUI theme structure, scoped to a React context provider
9
- * Override-able: all theme tokens/variables can be altered by consumers
10
- * Theme consumption via React hook and HOC methods
11
- * Color mode support as first-class consideration
12
- * "Light" and "dark" mode accounting
13
- * Theme consumption is scoped to the current color mode (set in the context provider)
14
- * Style adaptaion based on a smal set of base values
15
- * Text colors are calculated with WCAG Level AA (4.5:1) in mind
16
- * Scalable typographic and spacing rhythms
17
-
18
-
19
- ## Layers of the theme system
20
-
21
- ### Unbuilt theme
22
-
23
- _See [`euiThemeDefault`](../../themes/eui/theme.ts)_
24
- An unbuilt theme is a composed object of style values or `computed` functions.
25
-
26
- #### Style values
27
-
28
- Think design tokens or CSS property values. Ready to be consumed as-is in an application environment, using some JavaScript method of applying styles (i.e., a CSS-in-JS library is not required).
29
-
30
- #### `computed` functions
31
-
32
- These properties specify that the value depends upon some other value in the theme, in the shape of:
33
-
34
- ```js
35
- computed(
36
- ([size]) => size * 2 // predicate. What to do with the dependency values,
37
- ['sizes.euiSize'], // dependency array, referencing other properties in the theme object
38
- )
39
- ```
40
-
41
- The dependency array is optional. Omitting the array gives access to the computed theme.
42
-
43
- ```js
44
- computed(
45
- (theme) => theme.sizes.euiSize * 2
46
- )
47
- ```
48
-
49
- ### Theme system (built theme)
50
-
51
- _See [`EuiThemeDefault`](../../themes/eui/theme.ts)_
52
- A built theme by way of `buildTheme`, which transforms the object containing static style values and `computed` functions into a JavaScript Proxy object with handler traps. In this state, the theme is essentially inaccessible and immutable, that is, it requires `getComputed` to correctly order and access values and dependencies, and `set()` is disabled.
53
-
54
- ### Computed theme
55
-
56
- _See [`EuiThemeContext`](../../themes/eui/context.ts)_
57
- A consumable theme object in which all `computed` function values have been computed; all values are accessible and usable in an application environment.
58
- Returned from `getComputed`, in the shape of:
59
-
60
- ```js
61
- getComputed(
62
- EuiThemeDefault, // Theme system (Proxy)
63
- {}, // Modifications object
64
- 'light' // Color mode
65
- )
66
- ```
67
-
68
- #### Modifications
69
-
70
- Because the theme system (built theme) is immutable, modifications can only be made at compute time by providing overrides and extensions for theme property values. These modifications are passed to the `EuiThemeProvider` via the `modify` prop and should match the high-level object shape of the theme.
71
-
72
- #### Color mode
73
-
74
- Think light and dark mode. A theme has built-in color mode support, using the reserved `LIGHT` and `DARK` keys as a marker:
75
-
76
- ```js
77
- colors: {
78
- LIGHT: {...}
79
- DARK : {...}
80
- }
81
- ```
82
- The reserved color mode keys can be used at any level and location in a theme.
83
- `getComputed` will only compute and return values in the specified current color mode.
84
-
85
-
86
- ## React-specific context
87
-
88
- ### EuiThemeProvider
89
-
90
- _See [`EuiThemeProvider`](../../themes/eui/provider.ts)_
91
- Umbrella provider component that holds the various top-level theme configuration option providers: theme system, color mode, modifications; as well as the primary output provider: computed theme.
92
- The actual computation for computed theme values takes place at this level, where the three inputs are known (theme system, color mode, modifications) and the output (computed theme) can be cached for consumption. Input changes are captured and the output is recomputed.
93
-
94
- ```js
95
- <EuiThemeProvider
96
- theme={DefaultEuiTheme}
97
- colorMode="light"
98
- modify={{}}
99
- />
100
- ```
101
-
102
- All three props are optional. The default values for EUI will be used in the event that no configuration is provided. Note, however that colorMode switching will require consumers to maintain that app state.
103
-
104
- ### useEuiTheme
105
-
106
- _See [`useEuiTheme`](../../themes/eui/hooks.tsx)_
107
- A custom React hook that returns the computed theme. This hook is little more than a wrapper around the `useContext` hook, accessing three of the top-level providers: computed theme, color mode, and modifications.
108
-
109
- ```js
110
- const { euiTheme, colorMode, modifications } = useEuiTheme();
111
- ```
112
-
113
- The `euiTheme` variable has TypeScript support, which will result in IDE autocomplete availability.
114
-
115
- ### WithEuiTheme
116
- A higher-order-component that wraps `useEuiTheme` for React class components.
117
-
118
-
119
- ___
120
-
121
-
122
- ## Emotion
123
-
124
- [Emotion](https://emotion.sh/docs/introduction) is the CSS-in-JS library currently selected for use in EUI. Nothing in the EUI theming system is dependent upon Emotion packages, but the Emotion ecosystem will have impacts on generated styles.
125
-
126
- ### Composition
127
-
128
- * Prefer the use of [`css` prop](https://emotion.sh/docs/css-prop) construction over [styled-component-like](https://emotion.sh/docs/styled) component construction
129
- * Babel-based build accommodation
130
-
131
- ### Testing
132
-
133
- Snapshot testing ([as currently configured](https://emotion.sh/docs/testing#writing-a-test)) will result in generic `emotion-${n}` class names with the generated style object as part of the snapshot.
134
-
135
- * This seems good for EUI, but it also affects consumers
136
- * Consumers will need to use the `@emotion/jest` snapshot serializer to avoid class name churn.
137
- * Not ideal; unsure of any other solutions
138
- * During the conversion process, the snapshot diffs will look less than ideal when using `shallow` (a single wrapper element; DOM itself is unchanged):
139
-
140
- ```diff
141
- - <div
142
- - className="euiTableRowCell__mobileHeader euiTableRowCell--hideForDesktop"
143
- + <EmotionCssPropInternal
144
- + __EMOTION_LABEL_PLEASE_DO_NOT_USE__="EuiTableRowCell"
145
- + __EMOTION_TYPE_PLEASE_DO_NOT_USE__="td"
146
- + className="euiTableRowCell"
147
- + style={
148
- + Object {
149
- + "width": undefined,
150
- + }
151
- + }
152
- >
153
- ```