@longline/aqua-ui 1.0.150 → 1.0.151

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.
@@ -78,6 +78,7 @@ var TableBase = function (_a) {
78
78
  setTime(Math.random());
79
79
  });
80
80
  resizeObserver.observe(auxRef.current);
81
+ resizeObserver.observe(innerRef.current);
81
82
  return function () { return resizeObserver.disconnect(); };
82
83
  }, []);
83
84
  // If desired, scroll newly selected item into view.
@@ -0,0 +1,28 @@
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ /** @ignore */
4
+ className?: string;
5
+ /**
6
+ * Current value.
7
+ */
8
+ value: [Date, Date] | null;
9
+ /**
10
+ * Is control currently open?
11
+ */
12
+ open: boolean;
13
+ /**
14
+ * Is control transparent? This affects the position at which
15
+ * this Body opens.
16
+ */
17
+ transparent?: boolean;
18
+ /**
19
+ * Fired when a new range is selected.
20
+ */
21
+ onSelect: (value: [Date, Date]) => void;
22
+ styles: any;
23
+ attributes: any;
24
+ }
25
+ declare const Body: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<IProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
26
+ ref?: React.Ref<HTMLDivElement>;
27
+ }, never>> & string & Omit<React.ForwardRefExoticComponent<IProps & React.RefAttributes<HTMLDivElement>>, keyof React.Component<any, {}, any>>;
28
+ export { Body };
@@ -0,0 +1,101 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ import * as React from 'react';
17
+ import styled, { css } from 'styled-components';
18
+ import { Calendar } from './Calendar';
19
+ var BodyBase = React.forwardRef(function (props, ref) {
20
+ var valueToDate = function (index) {
21
+ if (props.value == null || !Array.isArray(props.value) || props.value.length != 2)
22
+ return null;
23
+ return props.value[index];
24
+ };
25
+ var getStartYear = function () {
26
+ var dStart = valueToDate(0);
27
+ if (dStart)
28
+ return dStart.getFullYear();
29
+ return (new Date()).getFullYear();
30
+ };
31
+ var getEndYear = function () {
32
+ var dStart = valueToDate(0);
33
+ var dEnd = valueToDate(1);
34
+ if (dStart == null)
35
+ return (new Date()).getFullYear() + 1;
36
+ if (dEnd) {
37
+ if (dEnd.getFullYear() <= dStart.getFullYear())
38
+ return dStart.getFullYear() + 1;
39
+ return dEnd.getFullYear();
40
+ }
41
+ return dStart.getFullYear() + 1;
42
+ };
43
+ // start and end are the currently selected start and end dates.
44
+ var _a = React.useState(valueToDate(0)), start = _a[0], setStart = _a[1];
45
+ var _b = React.useState(valueToDate(1)), end = _b[0], setEnd = _b[1];
46
+ // startYear and endYear are the years currently shown in the calendars.
47
+ var _c = React.useState(getStartYear()), startYear = _c[0], setStartYear = _c[1];
48
+ var _d = React.useState(getEndYear()), endYear = _d[0], setEndYear = _d[1];
49
+ React.useEffect(function () {
50
+ setStart(valueToDate(0));
51
+ setEnd(valueToDate(1));
52
+ setStartYear(getStartYear());
53
+ setEndYear(getEndYear());
54
+ }, [props.open]);
55
+ var handleChangeStartYear = function (year) {
56
+ setStartYear(year);
57
+ if (endYear <= year)
58
+ setEndYear(year + 1);
59
+ };
60
+ var handleChangeEndYear = function (year) {
61
+ setEndYear(year);
62
+ if (startYear >= year)
63
+ setStartYear(year - 1);
64
+ };
65
+ var handleSelectMonth = function (month, year) {
66
+ // No start date yet?
67
+ if (!start) {
68
+ var start_1 = new Date(year, month, 1);
69
+ setStart(start_1);
70
+ props.onSelect([start_1, start_1]);
71
+ }
72
+ // There is already a start date?
73
+ else if (!end) {
74
+ var newStart = start;
75
+ var newEnd = new Date(year, month + 1, 0); // Get last day of month
76
+ // Swap start/end if necessary.
77
+ if (newStart > newEnd) {
78
+ var temp = newStart;
79
+ newStart = newEnd;
80
+ newEnd = temp;
81
+ }
82
+ setStart(newStart);
83
+ setEnd(newEnd);
84
+ props.onSelect([newStart, newEnd]);
85
+ }
86
+ // There are both start and end dates. Clear and set start.
87
+ else {
88
+ setStart(new Date(year, month, 1));
89
+ setEnd(null);
90
+ props.onSelect([start, start]);
91
+ }
92
+ };
93
+ return (React.createElement("div", __assign({ style: props.styles.popper }, props.attributes.popper, { className: props.className, tabIndex: -1, ref: ref, onMouseDown: function (e) { return e.stopPropagation(); } }),
94
+ React.createElement(Calendars, null,
95
+ React.createElement(Calendar, { year: startYear, start: start, end: end, onChangeYear: handleChangeStartYear, onMonth: handleSelectMonth }),
96
+ React.createElement(Calendar, { year: endYear, start: start, end: end, onChangeYear: handleChangeEndYear, onMonth: handleSelectMonth }))));
97
+ });
98
+ var Calendars = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: row;\n gap: 8px;\n"], ["\n display: flex;\n flex-direction: row;\n gap: 8px;\n"])));
99
+ var Body = styled(BodyBase)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n z-index: 9999 !important;\n box-sizing: border-box;\n overflow-y: hidden;\n outline: none;\n\n background-color: ", ";\n border-radius: ", "px;\n color: ", ";\n\n transition: opacity ", "ms ease-in-out,\n max-height 0ms linear ", "ms;\n max-height: 0;\n opacity: 0;\n ", "\n"], ["\n z-index: 9999 !important;\n box-sizing: border-box;\n overflow-y: hidden;\n outline: none;\n\n background-color: ", ";\n border-radius: ", "px;\n color: ", ";\n\n transition: opacity ", "ms ease-in-out,\n max-height 0ms linear ", "ms;\n max-height: 0;\n opacity: 0;\n ", "\n"])), function (p) { return p.theme.colors.neutral[100]; }, function (p) { return p.theme.radius.normal; }, function (p) { return p.theme.colors.primary[3]; }, function (p) { return p.theme.animation.duration * 0; }, function (p) { return p.theme.animation.duration * 0; }, function (p) { return p.open && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n transition: opacity ", "ms ease-in,\n max-height 0ms linear;\n max-height: 1000px;\n opacity: 1;\n "], ["\n transition: opacity ", "ms ease-in,\n max-height 0ms linear;\n max-height: 1000px;\n opacity: 1;\n "])), function (p) { return p.theme.animation.duration; }); });
100
+ export { Body };
101
+ var templateObject_1, templateObject_2, templateObject_3;
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ /** @ignore */
4
+ className?: string;
5
+ /** Calendar year */
6
+ year: number;
7
+ /** Selected start date */
8
+ start: Date;
9
+ /** Selected end date */
10
+ end: Date;
11
+ /** Fired when calendar changes year */
12
+ onChangeYear: (year: number) => void;
13
+ /** Fired when month is clicked. */
14
+ onMonth: (month: number, year: number) => void;
15
+ }
16
+ declare const Calendar: (props: IProps) => React.JSX.Element;
17
+ export { Calendar };
@@ -0,0 +1,45 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ import * as React from 'react';
17
+ import styled, { css } from 'styled-components';
18
+ import { YearSelector } from './YearSelector';
19
+ var CalendarBase = function (props) {
20
+ var getMonthName = function (index) {
21
+ return ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][index % 12];
22
+ };
23
+ return (React.createElement("div", { className: props.className },
24
+ React.createElement(YearSelector, { year: props.year, onChange: props.onChangeYear }),
25
+ React.createElement(Months, null, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(function (month) {
26
+ var $start = props.start && props.start.getFullYear() == props.year && props.start.getMonth() == month;
27
+ var $end = props.end && props.end.getFullYear() == props.year && props.end.getMonth() == month;
28
+ var $between = props.start && props.start.getFullYear() * 12 + props.start.getMonth() < props.year * 12 + month &&
29
+ props.end && props.end.getFullYear() * 12 + props.end.getMonth() > props.year * 12 + month;
30
+ var $length = (props.start && props.end) ?
31
+ (props.end.getFullYear() * 12 + props.end.getMonth()) - (props.start.getFullYear() * 12 + props.start.getMonth())
32
+ : 0;
33
+ return (React.createElement(Month, { key: month, "$start": $start, "$end": $end, "$between": $between, "$length": $length, onClick: function () { return props.onMonth(month, props.year); } }, getMonthName(month)));
34
+ }))));
35
+ };
36
+ var CalendarStyled = styled(CalendarBase)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: 12px 16px 12px 16px;\n user-select: none;\n"], ["\n padding: 12px 16px 12px 16px;\n user-select: none;\n"])));
37
+ var Months = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: grid;\n grid-template-columns: repeat(4, 40px);\n grid-template-rows: repeat(3, 40px);\n row-gap: 4px;\n"], ["\n display: grid;\n grid-template-columns: repeat(4, 40px);\n grid-template-rows: repeat(3, 40px);\n row-gap: 4px;\n"])));
38
+ var Month = styled.div.attrs(function (p) {
39
+ return {
40
+ r: "50%" // Border radius one-time definition
41
+ };
42
+ })(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n position: relative;\n cursor: pointer;\n display: flex;\n justify-content: center;\n align-items: center;\n border-radius: ", ";\n\n // Set backgrounds and border radii.\n // Note: $between is neither start nor end, but between them.\n ", "\n ", " \n ", "\n ", "\n\n // Hover effect only on unselected months.\n ", "\n"], ["\n position: relative;\n cursor: pointer;\n display: flex;\n justify-content: center;\n align-items: center;\n border-radius: ", ";\n\n // Set backgrounds and border radii.\n // Note: $between is neither start nor end, but between them.\n ", "\n ", " \n ", "\n ", "\n\n // Hover effect only on unselected months.\n ", "\n"])), function (p) { return p.r; }, function (p) { return (p.$between || p.$start || p.$end) && css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background-color: ", ";\n color: ", ";\n "], ["\n background-color: ", ";\n color: ", ";\n "])), function (p) { return p.theme.colors.neutral[30]; }, function (p) { return p.theme.colors.neutral[100]; }); }, function (p) { return p.$between && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n border-radius: 0px;\n "], ["\n border-radius: 0px;\n "]))); }, function (p) { return p.$start && css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n border-top-left-radius: ", ";\n border-bottom-left-radius: ", ";\n border-top-right-radius: ", ";\n border-bottom-right-radius: ", ";\n "], ["\n border-top-left-radius: ", ";\n border-bottom-left-radius: ", ";\n border-top-right-radius: ", ";\n border-bottom-right-radius: ", ";\n "])), p.r, p.r, p.$length ? 0 : p.r, p.$length ? 0 : p.r); }, function (p) { return p.$end && css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n border-top-right-radius: ", ";\n border-bottom-right-radius: ", ";\n border-top-left-radius: ", ";\n border-bottom-left-radius: ", "; \n "], ["\n border-top-right-radius: ", ";\n border-bottom-right-radius: ", ";\n border-top-left-radius: ", ";\n border-bottom-left-radius: ", "; \n "])), p.r, p.r, p.$length ? 0 : p.r, p.$length ? 0 : p.r); }, function (p) { return (!p.$between && !p.$start && !p.$end) && css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n &:hover {\n background-color: rgb(from ", " r g b / 30%);\n }\n "], ["\n &:hover {\n background-color: rgb(from ", " r g b / 30%);\n }\n "])), function (p) { return p.theme.colors.primary[1]; }); });
43
+ var Calendar = function (props) { return React.createElement(CalendarStyled, __assign({}, props)); };
44
+ export { Calendar };
45
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
@@ -0,0 +1,71 @@
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ /** @ignore */
4
+ className?: string;
5
+ /**
6
+ * Input name for use in forms.
7
+ */
8
+ name?: string;
9
+ /**
10
+ * Current MonthRange value.
11
+ */
12
+ value?: [Date, Date] | null;
13
+ /**
14
+ * Marks MonthRange as disabled. Disabled MonthRanges cannot be interacted with.
15
+ * @default false
16
+ */
17
+ disabled?: boolean;
18
+ /**
19
+ * Removes input border and makes background transparent. This is useful
20
+ * for placing an input in a `Field`.
21
+ * @default false
22
+ */
23
+ transparent?: boolean;
24
+ /**
25
+ * A MonthRange can be in a ghost state, where content is being loaded.
26
+ * @default false
27
+ */
28
+ ghost?: boolean;
29
+ /**
30
+ * A fluid `MonthRange` takes up all available horizontal space available to it.
31
+ * @default false
32
+ */
33
+ fluid?: boolean;
34
+ /**
35
+ * A `MonthRange` can show an error state.
36
+ * @default false
37
+ */
38
+ error?: boolean;
39
+ /**
40
+ * If set, MonthRange's value can be cleared.
41
+ * @default false
42
+ */
43
+ clearable?: boolean;
44
+ /**
45
+ * The `MonthRange` opening direction can be either `up` or `down`.
46
+ * @default down
47
+ */
48
+ direction?: 'up' | 'down';
49
+ /**
50
+ * Optional placeholder text.
51
+ */
52
+ placeholder?: React.ReactNode;
53
+ /**
54
+ * If set, month count is displayed in selector.
55
+ * @default false
56
+ */
57
+ count?: boolean;
58
+ /**
59
+ * Listeners are notified whenever the user interacts with the `MonthRange`.
60
+ */
61
+ onChange?: (value: [Date, Date] | null) => void;
62
+ /**
63
+ * Listeners are notified when the `MonthRange` receives focus.
64
+ */
65
+ onFocus?: () => void;
66
+ }
67
+ /**
68
+ * A `MonthRange` allows a selection of a time period, measured in months.
69
+ */
70
+ declare const MonthRange: ({ direction, disabled, transparent, fluid, error, clearable, count, ...props }: IProps) => React.JSX.Element;
71
+ export { MonthRange, IProps };
@@ -0,0 +1,111 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ var __rest = (this && this.__rest) || function (s, e) {
17
+ var t = {};
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
+ t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
+ t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ };
27
+ import * as React from 'react';
28
+ import styled, { css } from 'styled-components';
29
+ import { createPortal } from 'react-dom';
30
+ import { usePopper } from 'react-popper';
31
+ import { Selector } from './Selector';
32
+ import { Body } from './Body';
33
+ var MonthRangeBase = function (props) {
34
+ var wrapperRef = React.useRef(null);
35
+ var bodyRef = React.useRef(null);
36
+ var _a = React.useState(props.value), value = _a[0], setValue = _a[1];
37
+ var _b = React.useState(false), open = _b[0], setOpen = _b[1];
38
+ // Add (and remove) document-wide event listener for mousedown.
39
+ React.useEffect(function () {
40
+ document.addEventListener('mousedown', handleClickOutside);
41
+ return function () { return document.removeEventListener('mousedown', handleClickOutside); };
42
+ }, []);
43
+ //
44
+ // Handle document-wide mousedown event by closing the Selector.
45
+ // (This only happens if there actually is a Selector).
46
+ //
47
+ var handleClickOutside = function (e) {
48
+ var elem = e.target;
49
+ if (wrapperRef.current && bodyRef.current && !wrapperRef.current.contains(elem) && !bodyRef.current.contains(elem)) {
50
+ setOpen(false);
51
+ }
52
+ };
53
+ // Open the dropdown.
54
+ var doOpen = function () {
55
+ setOpen(true);
56
+ };
57
+ var handleToggle = function () {
58
+ if (!open) {
59
+ doOpen();
60
+ // Update popper position.
61
+ if (update)
62
+ update();
63
+ }
64
+ else {
65
+ setOpen(false);
66
+ }
67
+ };
68
+ var handleSelect = function (newValue) {
69
+ setValue(newValue);
70
+ if (props.onChange)
71
+ props.onChange(newValue);
72
+ };
73
+ var handleKeyDown = function (e) {
74
+ if (props.disabled)
75
+ return;
76
+ if (props.ghost)
77
+ return;
78
+ if (e.key == ' ' && !open)
79
+ doOpen();
80
+ if (e.key == 'Escape' && open)
81
+ setOpen(false);
82
+ };
83
+ var _c = usePopper(wrapperRef.current, bodyRef.current, {
84
+ placement: props.direction == 'down' ? 'bottom-start' : 'top-start',
85
+ modifiers: [
86
+ {
87
+ name: 'offset',
88
+ options: {
89
+ offset: [0, props.transparent ? 30 : 8],
90
+ },
91
+ }
92
+ ]
93
+ }), styles = _c.styles, attributes = _c.attributes, update = _c.update;
94
+ return (React.createElement("div", { tabIndex: -1, className: props.className, onKeyDown: handleKeyDown, ref: wrapperRef },
95
+ React.createElement(Selector, { value: value, disabled: props.disabled, ghost: props.ghost, transparent: props.transparent, error: props.error, clearable: props.clearable, placeholder: props.placeholder, count: props.count, onClear: (!props.disabled && props.clearable && value != null) ? function () { return handleSelect(null); } : null, onCalendar: handleToggle }),
96
+ createPortal(React.createElement(Body, { ref: bodyRef, value: value, open: open, transparent: props.transparent, onSelect: handleSelect, styles: styles, attributes: attributes }), document.body)));
97
+ };
98
+ var MonthRangeStyled = styled(MonthRangeBase)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: relative;\n // MonthRange has a minimum width.\n width: 250px;\n // A fluid MonthRange occupies full horizontal width.\n ", " \n"], ["\n position: relative;\n // MonthRange has a minimum width.\n width: 250px;\n // A fluid MonthRange occupies full horizontal width.\n ", " \n"
99
+ /**
100
+ * A `MonthRange` allows a selection of a time period, measured in months.
101
+ */
102
+ ])), function (p) { return p.fluid && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["width: 100%;"], ["width: 100%;"]))); });
103
+ /**
104
+ * A `MonthRange` allows a selection of a time period, measured in months.
105
+ */
106
+ var MonthRange = function (_a) {
107
+ var _b = _a.direction, direction = _b === void 0 ? 'down' : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.transparent, transparent = _d === void 0 ? false : _d, _e = _a.fluid, fluid = _e === void 0 ? false : _e, _f = _a.error, error = _f === void 0 ? false : _f, _g = _a.clearable, clearable = _g === void 0 ? false : _g, _h = _a.count, count = _h === void 0 ? false : _h, props = __rest(_a, ["direction", "disabled", "transparent", "fluid", "error", "clearable", "count"]);
108
+ return React.createElement(MonthRangeStyled, __assign({ direction: direction, disabled: disabled, transparent: transparent, fluid: fluid, error: error, clearable: clearable, count: count }, props));
109
+ };
110
+ export { MonthRange };
111
+ var templateObject_1, templateObject_2;
@@ -0,0 +1,48 @@
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ /** @ignore */
4
+ className?: string;
5
+ /**
6
+ * Current input value.
7
+ */
8
+ value: [Date, Date];
9
+ /**
10
+ * Marks input as disabled. Disabled inputs cannot be interacted with.
11
+ * @default false
12
+ */
13
+ disabled?: boolean;
14
+ /**
15
+ * Removes input border and makes background transparent. This is useful
16
+ * for placing an input in a `Field`.
17
+ * @default false
18
+ */
19
+ transparent?: boolean;
20
+ /**
21
+ * Is DateInput ghosted?
22
+ * @default false
23
+ */
24
+ ghost?: boolean;
25
+ /**
26
+ * An input can show an error state.
27
+ * @default false
28
+ */
29
+ error?: boolean;
30
+ /**
31
+ * If set, Input's value can be cleared.
32
+ * @default false
33
+ */
34
+ clearable?: boolean;
35
+ /**
36
+ * Optional placeholder text.
37
+ */
38
+ placeholder?: React.ReactNode;
39
+ /**
40
+ * If set, month count is displayed in selector.
41
+ * @default false
42
+ */
43
+ count?: boolean;
44
+ onClear?: () => void;
45
+ onCalendar: () => void;
46
+ }
47
+ declare const Selector: (props: IProps) => React.JSX.Element;
48
+ export { Selector };
@@ -0,0 +1,61 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ import * as React from 'react';
6
+ import styled, { css, useTheme } from 'styled-components';
7
+ import { InputWrapper } from '../Input/InputWrapper';
8
+ import { SVG } from '../../svg';
9
+ import { DateTime } from '../../formatters/DateTime';
10
+ var Selector = function (props) {
11
+ var theme = useTheme();
12
+ var hasValue = function () {
13
+ if (props.value == null || !Array.isArray(props.value) || props.value.length != 2)
14
+ return false;
15
+ if (props.value[0] == null || props.value[1] == null)
16
+ return false;
17
+ return true;
18
+ };
19
+ var monthsDiff = function (d1, d2) {
20
+ return (d2.getFullYear() * 12 + d2.getMonth()) - (d1.getFullYear() * 12 + d1.getMonth()) + 1;
21
+ };
22
+ var renderDates = function () {
23
+ // No selection?
24
+ if (!hasValue())
25
+ return React.createElement(React.Fragment, null,
26
+ props.placeholder,
27
+ "\u00A0");
28
+ // Same year?
29
+ if (props.value[0].getFullYear() == props.value[1].getFullYear()) {
30
+ // Same month?
31
+ if (props.value[0].getMonth() == props.value[1].getMonth()) {
32
+ return React.createElement(React.Fragment, null,
33
+ React.createElement(DateTime, { type: "custom", format: "MMM yyyy", value: props.value[0] }));
34
+ }
35
+ else {
36
+ return React.createElement(React.Fragment, null,
37
+ React.createElement(DateTime, { type: "custom", format: "MMM", value: props.value[0] }),
38
+ " - ",
39
+ React.createElement(DateTime, { type: "custom", format: "MMM yyyy", value: props.value[1] }),
40
+ props.count && React.createElement("span", null,
41
+ " (",
42
+ monthsDiff(props.value[0], props.value[1]),
43
+ "m)"));
44
+ }
45
+ }
46
+ // Different years:
47
+ return React.createElement(React.Fragment, null,
48
+ React.createElement(DateTime, { type: "custom", format: "MMM yyyy", value: props.value[0] }),
49
+ " - ",
50
+ React.createElement(DateTime, { type: "custom", format: "MMM yyyy", value: props.value[1] }),
51
+ props.count && React.createElement("span", null,
52
+ " (",
53
+ monthsDiff(props.value[0], props.value[1]),
54
+ "m)"));
55
+ };
56
+ return (React.createElement(InputWrapper, { fluid: true, error: props.error, disabled: props.disabled, ghost: props.ghost, transparent: props.transparent, onClear: (props.clearable && hasValue()) ? props.onClear : null, onClick: props.onCalendar, icon: { url: SVG.Icons.Calendar, color: theme.colors.primary[3] }, iconPosition: 'right' },
57
+ React.createElement(Selection, { "$placeholder": !hasValue() }, renderDates())));
58
+ };
59
+ var Selection = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n width: 100%;\n outline: none;\n overflow-x: hidden;\n overflow-y: hidden;\n white-space: nowrap;\n ", " \n"], ["\n width: 100%;\n outline: none;\n overflow-x: hidden;\n overflow-y: hidden;\n white-space: nowrap;\n ", " \n"])), function (p) { return p.$placeholder && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n color: rgb(from ", " r g b / 50%);\n "], ["\n color: rgb(from ", " r g b / 50%);\n "])), function (p) { return p.theme.colors.primary[3]; }); });
60
+ export { Selector };
61
+ var templateObject_1, templateObject_2;
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ /** @ignore */
4
+ className?: string;
5
+ /** Current year */
6
+ year: number;
7
+ /** Fired when year is changed. */
8
+ onChange: (year: number) => void;
9
+ }
10
+ declare const YearSelector: (props: IProps) => React.JSX.Element;
11
+ export { YearSelector };
@@ -0,0 +1,38 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ import * as React from 'react';
17
+ import styled from 'styled-components';
18
+ import { Icon } from '../../controls/Icon';
19
+ import { SVG } from '../../svg';
20
+ var YearSelectorBase = function (props) {
21
+ var handleChangeYear = function (newYear) {
22
+ if (newYear < 0 || newYear > 9999)
23
+ return;
24
+ props.onChange(newYear);
25
+ };
26
+ return (React.createElement("div", { className: props.className },
27
+ React.createElement(Year, null, props.year),
28
+ React.createElement(Button, null,
29
+ React.createElement(Icon, { url: SVG.Icons.Chevron, size: 'large', onClick: function () { return handleChangeYear(props.year - 1); } })),
30
+ React.createElement(Button, null,
31
+ React.createElement(Icon, { url: SVG.Icons.Chevron, size: 'large', rotated: 180, onClick: function () { return handleChangeYear(props.year + 1); } }))));
32
+ };
33
+ var Year = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font: ", ";\n font-weight: 700;\n user-select: none;\n padding-left: 8px;\n"], ["\n font: ", ";\n font-weight: 700;\n user-select: none;\n padding-left: 8px;\n"])), function (p) { return p.theme.font.labelSmall; });
34
+ var Button = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n width: 28px;\n height: 28px;\n display: flex;\n justify-content: center;\n align-items: center;\n transition: background-color ease-in-out ", "ms;\n border-radius: ", "px;\n svg {\n fill: ", ";\n }\n &:hover {\n background-color: rgb(from ", " r g b / 30%);\n svg {\n fill: ", ";\n } \n }\n"], ["\n width: 28px;\n height: 28px;\n display: flex;\n justify-content: center;\n align-items: center;\n transition: background-color ease-in-out ", "ms;\n border-radius: ", "px;\n svg {\n fill: ", ";\n }\n &:hover {\n background-color: rgb(from ", " r g b / 30%);\n svg {\n fill: ", ";\n } \n }\n"])), function (p) { return p.theme.animation.duration; }, function (p) { return p.theme.radius.normal; }, function (p) { return p.theme.colors.neutral[10]; }, function (p) { return p.theme.colors.primary[1]; }, function (p) { return p.theme.colors.neutral[10]; });
35
+ var YearSelectorStyled = styled(YearSelectorBase)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: grid;\n grid-template-columns: 1fr 32px 32px;\n align-items: center;\n"], ["\n display: grid;\n grid-template-columns: 1fr 32px 32px;\n align-items: center;\n"])));
36
+ var YearSelector = function (props) { return React.createElement(YearSelectorStyled, __assign({}, props)); };
37
+ export { YearSelector };
38
+ var templateObject_1, templateObject_2, templateObject_3;
@@ -0,0 +1 @@
1
+ export * from './MonthRange';
@@ -0,0 +1 @@
1
+ export * from './MonthRange';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.150",
3
+ "version": "1.0.151",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",