etudes 0.34.0 → 0.35.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.
@@ -1,25 +1,94 @@
1
1
  import { CSSProperties, PureComponent } from 'react';
2
2
  export interface Props {
3
+ /**
4
+ * Class attribute of the root element.
5
+ */
3
6
  className?: string;
7
+ /**
8
+ * Inline style attribute of the root element.
9
+ */
4
10
  style?: CSSProperties;
11
+ /**
12
+ * Indicates whether selections can be toggled. For example, in the case of
13
+ * a vertical list of selectable rows, being able to toggle a row means it
14
+ * gets deselected when selected again. Being unable to toggle the row means
15
+ * it does not get deselected when selected again.
16
+ */
5
17
  isTogglable?: boolean;
18
+ /**
19
+ * Indicates whether selections are retained. For example, in the case of
20
+ * a vertical list of clickable rows, being able to retain a selection means
21
+ * when the row is clicked, it becomes and stays selected. Being unable to
22
+ * retain a selection means when the row is clicked, it does not become
23
+ * selected. It is simply clicked and the subsequent event is dispatched.
24
+ */
6
25
  shouldStaySelected?: boolean;
26
+ /**
27
+ * The default selected index. Any value below 0 indicates that nothing is
28
+ * selected.
29
+ */
7
30
  defaultSelectedIndex?: number;
31
+ /**
32
+ * Handler invoked when an index is deselected.
33
+ */
8
34
  onDeselectAt?: (index: number) => void;
35
+ /**
36
+ * Handler invoked when an index is selected.
37
+ */
9
38
  onSelectAt?: (index: number) => void;
10
39
  }
11
40
  export interface State {
41
+ /**
42
+ * The current selected index. Any value less than 0 indicates that no index
43
+ * is selected.
44
+ */
12
45
  selectedIndex?: number;
13
46
  }
47
+ /**
48
+ * An abstract component that mimics and handles index selection in an abstract
49
+ * collection.
50
+ */
14
51
  export default class AbstractSelectableCollection<P extends Props = Props, S extends State = State> extends PureComponent<P, S> {
15
52
  constructor(props: P);
16
53
  componentDidMount(): void;
17
54
  componentDidUpdate(prevProps: P, prevState: S): void;
18
55
  render(): JSX.Element;
56
+ /**
57
+ * Checks if an index is out of range.
58
+ *
59
+ * @param index - The index to check.
60
+ *
61
+ * @returns `true` if the index is out of range, `false` otherwise.
62
+ */
19
63
  isIndexOutOfRange(index: number): boolean;
64
+ /**
65
+ * Checks if an index is selected.
66
+ *
67
+ * @param index - The index to check.
68
+ *
69
+ * @returns `true` if the index is selected, `false` otherwise.
70
+ */
20
71
  isSelectedAt(index: number): boolean;
72
+ /**
73
+ * Toggles an index, i.e. reverses its selected state.
74
+ *
75
+ * @param index - The index to toggle.
76
+ */
21
77
  toggleAt(index: number): void;
78
+ /**
79
+ * Selects an index.
80
+ *
81
+ * @param index - The index to select.
82
+ */
22
83
  selectAt(index: number): void;
84
+ /**
85
+ * Deselects an index if it is currently selected.
86
+ *
87
+ * @param index - The index to deselect.
88
+ */
23
89
  deselectAt(index: number): void;
90
+ /**
91
+ * Deselects the currently selected index.
92
+ */
24
93
  deselectCurrent(): void;
25
94
  }
@@ -36,7 +36,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  var react_1 = __importStar(require("react"));
38
38
  var debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:asc') : function () { };
39
- var AbstractSelectableCollection = (function (_super) {
39
+ /**
40
+ * An abstract component that mimics and handles index selection in an abstract
41
+ * collection.
42
+ */
43
+ var AbstractSelectableCollection = /** @class */ (function (_super) {
40
44
  __extends(AbstractSelectableCollection, _super);
41
45
  function AbstractSelectableCollection(props) {
42
46
  var _a;
@@ -70,14 +74,33 @@ var AbstractSelectableCollection = (function (_super) {
70
74
  AbstractSelectableCollection.prototype.render = function () {
71
75
  return react_1.default.createElement(react_1.Fragment, null);
72
76
  };
77
+ /**
78
+ * Checks if an index is out of range.
79
+ *
80
+ * @param index - The index to check.
81
+ *
82
+ * @returns `true` if the index is out of range, `false` otherwise.
83
+ */
73
84
  AbstractSelectableCollection.prototype.isIndexOutOfRange = function (index) {
74
85
  if (index < 0)
75
86
  return true;
76
87
  return false;
77
88
  };
89
+ /**
90
+ * Checks if an index is selected.
91
+ *
92
+ * @param index - The index to check.
93
+ *
94
+ * @returns `true` if the index is selected, `false` otherwise.
95
+ */
78
96
  AbstractSelectableCollection.prototype.isSelectedAt = function (index) {
79
97
  return (this.state.selectedIndex === index);
80
98
  };
99
+ /**
100
+ * Toggles an index, i.e. reverses its selected state.
101
+ *
102
+ * @param index - The index to toggle.
103
+ */
81
104
  AbstractSelectableCollection.prototype.toggleAt = function (index) {
82
105
  if (this.props.isTogglable === true && this.isSelectedAt(index)) {
83
106
  this.deselectAt(index);
@@ -86,6 +109,11 @@ var AbstractSelectableCollection = (function (_super) {
86
109
  this.selectAt(index);
87
110
  }
88
111
  };
112
+ /**
113
+ * Selects an index.
114
+ *
115
+ * @param index - The index to select.
116
+ */
89
117
  AbstractSelectableCollection.prototype.selectAt = function (index) {
90
118
  if (this.props.shouldStaySelected === true) {
91
119
  if (this.isSelectedAt(index))
@@ -96,11 +124,19 @@ var AbstractSelectableCollection = (function (_super) {
96
124
  this.props.onSelectAt(index);
97
125
  }
98
126
  };
127
+ /**
128
+ * Deselects an index if it is currently selected.
129
+ *
130
+ * @param index - The index to deselect.
131
+ */
99
132
  AbstractSelectableCollection.prototype.deselectAt = function (index) {
100
133
  if (!this.isSelectedAt(index))
101
134
  return;
102
135
  this.setState({ selectedIndex: -1 });
103
136
  };
137
+ /**
138
+ * Deselects the currently selected index.
139
+ */
104
140
  AbstractSelectableCollection.prototype.deselectCurrent = function () {
105
141
  this.setState({ selectedIndex: -1 });
106
142
  };
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractSelectableCollection.js","sourceRoot":"/","sources":["AbstractSelectableCollection.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAqE;AAErE,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,cAAO,CAAC,CAAA;AA2DhG;IA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,CAA4G,qBAAa,GAsGxH","sourcesContent":["import React, { CSSProperties, Fragment, PureComponent } from 'react'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:asc') : () => {}\n\nexport interface Props {\n /**\n * Class attribute of the root element.\n */\n className?: string\n\n /**\n * Inline style attribute of the root element.\n */\n style?: CSSProperties\n\n /**\n * Indicates whether selections can be toggled. For example, in the case of\n * a vertical list of selectable rows, being able to toggle a row means it\n * gets deselected when selected again. Being unable to toggle the row means\n * it does not get deselected when selected again.\n */\n isTogglable?: boolean\n\n /**\n * Indicates whether selections are retained. For example, in the case of\n * a vertical list of clickable rows, being able to retain a selection means\n * when the row is clicked, it becomes and stays selected. Being unable to\n * retain a selection means when the row is clicked, it does not become\n * selected. It is simply clicked and the subsequent event is dispatched.\n */\n shouldStaySelected?: boolean\n\n /**\n * The default selected index. Any value below 0 indicates that nothing is\n * selected.\n */\n defaultSelectedIndex?: number\n\n /**\n * Handler invoked when an index is deselected.\n */\n onDeselectAt?: (index: number) => void\n\n /**\n * Handler invoked when an index is selected.\n */\n onSelectAt?: (index: number) => void\n}\n\nexport interface State {\n /**\n * The current selected index. Any value less than 0 indicates that no index\n * is selected.\n */\n selectedIndex?: number\n}\n\n/**\n * An abstract component that mimics and handles index selection in an abstract\n * collection.\n */\nexport default class AbstractSelectableCollection<P extends Props = Props, S extends State = State> extends PureComponent<P, S> {\n constructor(props: P) {\n super(props)\n\n this.state = {\n selectedIndex: this.props.defaultSelectedIndex ?? -1,\n } as any\n }\n\n componentDidMount() {\n if (this.state.selectedIndex !== undefined && this.state.selectedIndex > -1) {\n this.props.onSelectAt?.(this.state.selectedIndex ?? -1)\n }\n }\n\n componentDidUpdate(prevProps: P, prevState: S) {\n const { shouldStaySelected, onSelectAt, onDeselectAt } = this.props\n const prevSelectedIndex = prevState.selectedIndex ?? -1\n const selectedIndex = this.state.selectedIndex ?? -1\n\n if (prevState.selectedIndex !== selectedIndex) {\n debug(`Selected index changed: ${selectedIndex}`)\n\n if (shouldStaySelected === true) {\n if (!this.isIndexOutOfRange(prevSelectedIndex)) onDeselectAt?.(prevSelectedIndex)\n if (!this.isIndexOutOfRange(selectedIndex)) onSelectAt?.(selectedIndex)\n }\n }\n }\n\n render() {\n return <Fragment/>\n }\n\n /**\n * Checks if an index is out of range.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is out of range, `false` otherwise.\n */\n isIndexOutOfRange(index: number): boolean {\n if (index < 0) return true\n return false\n }\n\n /**\n * Checks if an index is selected.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is selected, `false` otherwise.\n */\n isSelectedAt(index: number): boolean {\n return (this.state.selectedIndex === index)\n }\n\n /**\n * Toggles an index, i.e. reverses its selected state.\n *\n * @param index - The index to toggle.\n */\n toggleAt(index: number) {\n if (this.props.isTogglable === true && this.isSelectedAt(index)) {\n this.deselectAt(index)\n }\n else {\n this.selectAt(index)\n }\n }\n\n /**\n * Selects an index.\n *\n * @param index - The index to select.\n */\n selectAt(index: number) {\n if (this.props.shouldStaySelected === true) {\n if (this.isSelectedAt(index)) return\n this.setState({ selectedIndex: index })\n }\n else if (this.props.onSelectAt) {\n this.props.onSelectAt(index)\n }\n }\n\n /**\n * Deselects an index if it is currently selected.\n *\n * @param index - The index to deselect.\n */\n deselectAt(index: number) {\n if (!this.isSelectedAt(index)) return\n this.setState({ selectedIndex: -1 })\n }\n\n /**\n * Deselects the currently selected index.\n */\n deselectCurrent() {\n this.setState({ selectedIndex: -1 })\n }\n}\n"]}
1
+ {"version":3,"file":"AbstractSelectableCollection.js","sourceRoot":"/","sources":["AbstractSelectableCollection.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAqE;AAErE,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,cAAO,CAAC,CAA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,CAAC,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;IACtC,CAAC;IACH,mCAAC;AAAD,CAAC,AAtGD,CAA4G,qBAAa,GAsGxH","sourcesContent":["import React, { CSSProperties, Fragment, PureComponent } from 'react'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:asc') : () => {}\n\nexport interface Props {\n /**\n * Class attribute of the root element.\n */\n className?: string\n\n /**\n * Inline style attribute of the root element.\n */\n style?: CSSProperties\n\n /**\n * Indicates whether selections can be toggled. For example, in the case of\n * a vertical list of selectable rows, being able to toggle a row means it\n * gets deselected when selected again. Being unable to toggle the row means\n * it does not get deselected when selected again.\n */\n isTogglable?: boolean\n\n /**\n * Indicates whether selections are retained. For example, in the case of\n * a vertical list of clickable rows, being able to retain a selection means\n * when the row is clicked, it becomes and stays selected. Being unable to\n * retain a selection means when the row is clicked, it does not become\n * selected. It is simply clicked and the subsequent event is dispatched.\n */\n shouldStaySelected?: boolean\n\n /**\n * The default selected index. Any value below 0 indicates that nothing is\n * selected.\n */\n defaultSelectedIndex?: number\n\n /**\n * Handler invoked when an index is deselected.\n */\n onDeselectAt?: (index: number) => void\n\n /**\n * Handler invoked when an index is selected.\n */\n onSelectAt?: (index: number) => void\n}\n\nexport interface State {\n /**\n * The current selected index. Any value less than 0 indicates that no index\n * is selected.\n */\n selectedIndex?: number\n}\n\n/**\n * An abstract component that mimics and handles index selection in an abstract\n * collection.\n */\nexport default class AbstractSelectableCollection<P extends Props = Props, S extends State = State> extends PureComponent<P, S> {\n constructor(props: P) {\n super(props)\n\n this.state = {\n selectedIndex: this.props.defaultSelectedIndex ?? -1,\n } as any\n }\n\n componentDidMount() {\n if (this.state.selectedIndex !== undefined && this.state.selectedIndex > -1) {\n this.props.onSelectAt?.(this.state.selectedIndex ?? -1)\n }\n }\n\n componentDidUpdate(prevProps: P, prevState: S) {\n const { shouldStaySelected, onSelectAt, onDeselectAt } = this.props\n const prevSelectedIndex = prevState.selectedIndex ?? -1\n const selectedIndex = this.state.selectedIndex ?? -1\n\n if (prevState.selectedIndex !== selectedIndex) {\n debug(`Selected index changed: ${selectedIndex}`)\n\n if (shouldStaySelected === true) {\n if (!this.isIndexOutOfRange(prevSelectedIndex)) onDeselectAt?.(prevSelectedIndex)\n if (!this.isIndexOutOfRange(selectedIndex)) onSelectAt?.(selectedIndex)\n }\n }\n }\n\n render() {\n return <Fragment/>\n }\n\n /**\n * Checks if an index is out of range.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is out of range, `false` otherwise.\n */\n isIndexOutOfRange(index: number): boolean {\n if (index < 0) return true\n return false\n }\n\n /**\n * Checks if an index is selected.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is selected, `false` otherwise.\n */\n isSelectedAt(index: number): boolean {\n return (this.state.selectedIndex === index)\n }\n\n /**\n * Toggles an index, i.e. reverses its selected state.\n *\n * @param index - The index to toggle.\n */\n toggleAt(index: number) {\n if (this.props.isTogglable === true && this.isSelectedAt(index)) {\n this.deselectAt(index)\n }\n else {\n this.selectAt(index)\n }\n }\n\n /**\n * Selects an index.\n *\n * @param index - The index to select.\n */\n selectAt(index: number) {\n if (this.props.shouldStaySelected === true) {\n if (this.isSelectedAt(index)) return\n this.setState({ selectedIndex: index })\n }\n else if (this.props.onSelectAt) {\n this.props.onSelectAt(index)\n }\n }\n\n /**\n * Deselects an index if it is currently selected.\n *\n * @param index - The index to deselect.\n */\n deselectAt(index: number) {\n if (!this.isSelectedAt(index)) return\n this.setState({ selectedIndex: -1 })\n }\n\n /**\n * Deselects the currently selected index.\n */\n deselectCurrent() {\n this.setState({ selectedIndex: -1 })\n }\n}\n"]}
@@ -1,6 +1,10 @@
1
1
  import React, { ComponentType, CSSProperties, PureComponent } from 'react';
2
2
  import List, { ItemComponentProps as ListItemComponentProps } from './List';
3
3
  import { ExtendedCSSFunction, Orientation } from './types';
4
+ /**
5
+ * Interface defining the props of the item component type to be provided to the
6
+ * component. The data type is generic.
7
+ */
4
8
  export declare type ItemComponentProps<T = Record<string, never>> = ListItemComponentProps<T>;
5
9
  export declare type SectionHeaderCSSProps = Readonly<{
6
10
  borderColor: string;
@@ -17,27 +21,96 @@ export interface SectionProps<T = Record<string, never>> {
17
21
  items: T[];
18
22
  }
19
23
  export interface Props<T = Record<string, never>> {
24
+ /**
25
+ * Class attribute to the root element.
26
+ */
20
27
  className?: string;
28
+ /**
29
+ * Inline style attribute to the element.
30
+ */
21
31
  style?: CSSProperties;
32
+ /**
33
+ * Data provided to each section.
34
+ */
22
35
  data: SectionProps<T>[];
36
+ /**
37
+ * Indicates if sections can be toggled, as in, once a section is expanded,
38
+ * it collapses when being selected again.
39
+ */
23
40
  isTogglable?: boolean;
41
+ /**
42
+ * Index of the section that is selected by default. Any value less than 0
43
+ * indicates that no section is selected by default.
44
+ */
24
45
  defaultSelectedSectionIndex?: number;
46
+ /**
47
+ * Length (in pixels) of each item. This does not apply to the section hedaer
48
+ * itself. Length refers to the height in vertical orientation and width in
49
+ * horizontal orientation.
50
+ */
25
51
  itemLength?: number;
52
+ /**
53
+ * Padding (in pixels) between each item.
54
+ */
26
55
  itemPadding?: number;
56
+ /**
57
+ * Padding (in pixels) between each section.
58
+ */
27
59
  sectionPadding?: number;
60
+ /**
61
+ * Maximum number of items that are viside when a section expands. When a
62
+ * value greater than or equal to 0 is specified, only that number of items
63
+ * will be visible at a time, and a scrollbar will appear to scroll to
64
+ * remaining items. Any value less than 0 indicates that all items will be
65
+ * visible when a section expands.
66
+ */
28
67
  maxVisibleItems?: number;
68
+ /**
69
+ * Orientation of the component.
70
+ */
29
71
  orientation?: Orientation;
72
+ /**
73
+ * Color of the border of every item and the section header itself.
74
+ */
30
75
  borderColor?: string;
76
+ /**
77
+ * Thickness of the border (in pixels) of every item and the section header
78
+ * itself. 0 indicates no borders.
79
+ */
31
80
  borderThickness?: number;
81
+ /**
82
+ * SVG markup to be put in the section header as the expand icon.
83
+ */
32
84
  expandIconSvg?: string;
85
+ /**
86
+ * React component type to be used for generating items inside the component.
87
+ */
33
88
  itemComponentType: ComponentType<ItemComponentProps<T>>;
89
+ /**
90
+ * Handler invoked when the selected item index of any section changes.
91
+ */
34
92
  onItemIndexChange?: (index: number) => void;
93
+ /**
94
+ * Handler invoked when the selected section index changes.
95
+ */
35
96
  onSectionIndexChange?: (index: number) => void;
97
+ /**
98
+ * Additional CSS to be provided to each section element.
99
+ */
36
100
  sectionCSS?: ExtendedCSSFunction<SectionCSSProps>;
101
+ /**
102
+ * Additional CSS to be provided to each section header element.
103
+ */
37
104
  sectionHeaderCSS?: ExtendedCSSFunction<SectionHeaderCSSProps>;
38
105
  }
39
106
  export interface State {
107
+ /**
108
+ * Current selected section index.
109
+ */
40
110
  selectedSectionIndex: number;
111
+ /**
112
+ * Current selected item index of the expanded section.
113
+ */
41
114
  selectedItemIndex: number;
42
115
  }
43
116
  export default class Accordion<T = Record<string, never>> extends PureComponent<Props<T>, State> {
package/lib/Accordion.js CHANGED
@@ -67,7 +67,7 @@ var react_1 = __importStar(require("react"));
67
67
  var styled_components_1 = __importStar(require("styled-components"));
68
68
  var List_1 = __importDefault(require("./List"));
69
69
  var debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:accordion') : function () { };
70
- var Accordion = (function (_super) {
70
+ var Accordion = /** @class */ (function (_super) {
71
71
  __extends(Accordion, _super);
72
72
  function Accordion(props) {
73
73
  var _a;
@@ -68,7 +68,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
68
68
  Object.defineProperty(exports, "__esModule", { value: true });
69
69
  var react_1 = __importStar(require("react"));
70
70
  var styled_components_1 = __importDefault(require("styled-components"));
71
- var BurgerButton = (function (_super) {
71
+ var BurgerButton = /** @class */ (function (_super) {
72
72
  __extends(BurgerButton, _super);
73
73
  function BurgerButton(props) {
74
74
  var _this = _super.call(this, props) || this;
@@ -79,7 +79,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
79
79
  Object.defineProperty(exports, "__esModule", { value: true });
80
80
  var react_1 = __importStar(require("react"));
81
81
  var styled_components_1 = __importDefault(require("styled-components"));
82
- var DebugConsole = (function (_super) {
82
+ var DebugConsole = /** @class */ (function (_super) {
83
83
  __extends(DebugConsole, _super);
84
84
  function DebugConsole(props) {
85
85
  var _this = _super.call(this, props) || this;
package/lib/Dial.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ /// <reference types="react" />
2
+ import { CSSProp, CSSProperties } from 'styled-components';
3
+ export interface Props {
4
+ /**
5
+ * ID attribute of the root element.
6
+ */
7
+ id?: string;
8
+ /**
9
+ * Class attribute of the component.
10
+ */
11
+ className?: string;
12
+ /**
13
+ * Inline style attribute of the root element.
14
+ */
15
+ style?: CSSProperties;
16
+ /**
17
+ * Current angle reading of the compass, between 0.0 - 360.0 degrees, inclusive.
18
+ */
19
+ angle?: number;
20
+ /**
21
+ * Length of the knob along the track expressed in degrees, between 0.0 and 360.0 degrees,
22
+ * exclusive. If set to 0 or 360, the knob disappears.
23
+ *
24
+ * @example Suppose the compass were to be used to control a photosphere of an image that is 1000
25
+ * x 500, and the window size is 500 x 500, that would mean the FOV is 500 / 1000 * 360 =
26
+ * 180 degrees.
27
+ */
28
+ knobLength?: number;
29
+ /**
30
+ * Radius of the compass.
31
+ */
32
+ radius?: number;
33
+ /**
34
+ * The thickness of the knob, which is equivalent to the `stroke-width` of the `<path>` element.
35
+ * Note that this overwrites the `stroke-width` set inside `knobCSS`.
36
+ */
37
+ knobThickness?: number;
38
+ /**
39
+ * CSS of the knob, which is a `<path>` element.
40
+ */
41
+ knobCSS?: CSSProp<any>;
42
+ /**
43
+ * The thickness of the circular track, which is equivalent to the `stroke-width` of the
44
+ * `<circle>` element. Note that this overwrites the `stroke-width` set inside `trackCSS`.
45
+ */
46
+ trackThickness?: number;
47
+ /**
48
+ * CSS of the track, which is a `<circle>` element.
49
+ */
50
+ trackCSS?: CSSProp<any>;
51
+ }
52
+ /**
53
+ * A circular dial with a knob and a track.
54
+ */
55
+ export default function Dial({ id, className, style, angle, radius, knobLength, knobThickness, knobCSS, trackThickness, trackCSS, }: Props): JSX.Element;
package/lib/Dial.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var react_1 = __importDefault(require("react"));
22
+ var styled_components_1 = __importDefault(require("styled-components"));
23
+ function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
24
+ var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
25
+ return {
26
+ x: centerX + (radius * Math.cos(angleInRadians)),
27
+ y: centerY + (radius * Math.sin(angleInRadians)),
28
+ };
29
+ }
30
+ function arcPath(x, y, radius, startAngle, endAngle) {
31
+ var start = polarToCartesian(x, y, radius, endAngle);
32
+ var end = polarToCartesian(x, y, radius, startAngle);
33
+ var largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';
34
+ var d = [
35
+ 'M', start.x, start.y,
36
+ 'A', radius, radius, 0, largeArcFlag, 0, end.x, end.y,
37
+ ];
38
+ return d.join(' ');
39
+ }
40
+ /**
41
+ * A circular dial with a knob and a track.
42
+ */
43
+ function Dial(_a) {
44
+ var id = _a.id, className = _a.className, style = _a.style, _b = _a.angle, angle = _b === void 0 ? 0 : _b, _c = _a.radius, radius = _c === void 0 ? 50 : _c, _d = _a.knobLength, knobLength = _d === void 0 ? 30 : _d, _e = _a.knobThickness, knobThickness = _e === void 0 ? 10 : _e, knobCSS = _a.knobCSS, _f = _a.trackThickness, trackThickness = _f === void 0 ? 2 : _f, trackCSS = _a.trackCSS;
45
+ var diameter = radius * 2;
46
+ var clampedKnobAngle = Math.max(0, Math.min(360, knobLength));
47
+ return (react_1.default.createElement(StyledRoot, { id: id, className: className, style: __assign(__assign({}, style), { width: "".concat(diameter, "px"), height: "".concat(diameter, "px") }) },
48
+ react_1.default.createElement(StyledTrack, null,
49
+ react_1.default.createElement("svg", { width: diameter, height: diameter, viewBox: "0 0 ".concat(diameter, " ").concat(diameter) },
50
+ react_1.default.createElement(StyledTrackCircle, { cx: radius, cy: radius, r: radius - trackThickness / 2, css: trackCSS, strokeWidth: trackThickness }))),
51
+ react_1.default.createElement(StyledKnob, { style: { transform: "rotate(".concat((angle + 360) % 360, "deg)") } },
52
+ react_1.default.createElement("svg", { viewBox: "0 0 ".concat(diameter, " ").concat(diameter), xmlns: 'http://www.w3.org/2000/svg' },
53
+ react_1.default.createElement(StyledKnobPath, { css: knobCSS, strokeWidth: knobThickness, d: arcPath(radius, radius, radius - knobThickness / 2 - (trackThickness - knobThickness) / 2, -clampedKnobAngle / 2, clampedKnobAngle / 2) })))));
54
+ }
55
+ exports.default = Dial;
56
+ var StyledTrack = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n"], ["\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n"])));
57
+ var StyledTrackCircle = styled_components_1.default.circle(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n stroke-dasharray: 4;\n stroke: #fff;\n ", "\n"], ["\n stroke-dasharray: 4;\n stroke: #fff;\n ", "\n"])), function (props) { return props.css; });
58
+ var StyledKnob = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background-position: center;\n background-repeat: no-repeat;\n background-size: 100%;\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n\n svg {\n overflow: visible;\n position: absolute;\n right: 0;\n top: 0;\n }\n"], ["\n background-position: center;\n background-repeat: no-repeat;\n background-size: 100%;\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n\n svg {\n overflow: visible;\n position: absolute;\n right: 0;\n top: 0;\n }\n"])));
59
+ var StyledKnobPath = styled_components_1.default.path(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n stroke: #fff;\n ", "\n"], ["\n stroke: #fff;\n ", "\n"])), function (props) { return props.css; });
60
+ var StyledRoot = styled_components_1.default.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n box-sizing: border-box;\n display: block;\n"], ["\n box-sizing: border-box;\n display: block;\n"])));
61
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
62
+ //# sourceMappingURL=Dial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dial.js","sourceRoot":"/","sources":["Dial.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,gDAAyB;AACzB,wEAAkE;AA6DlE,SAAS,gBAAgB,CAAC,OAAe,EAAE,OAAe,EAAE,MAAc,EAAE,cAAsB;IAChG,IAAM,cAAc,GAAG,CAAC,cAAc,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,KAAK,CAAA;IAE9D,OAAO;QACL,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAChD,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;KACjD,CAAA;AACH,CAAC;AAED,SAAS,OAAO,CAAC,CAAS,EAAE,CAAS,EAAE,MAAc,EAAE,UAAkB,EAAE,QAAgB;IACzF,IAA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KADG,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,GAAG,EAAT,CAAS,CACrB,CAAA;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,qHAAA,kDAG5B,IAAA,CAAA","sourcesContent":["import React from 'react'\nimport styled, { CSSProp, CSSProperties } from 'styled-components'\n\nexport interface Props {\n /**\n * ID attribute of the root element.\n */\n id?: string\n\n /**\n * Class attribute of the component.\n */\n className?: string\n\n /**\n * Inline style attribute of the root element.\n */\n style?: CSSProperties\n\n /**\n * Current angle reading of the compass, between 0.0 - 360.0 degrees, inclusive.\n */\n angle?: number\n\n /**\n * Length of the knob along the track expressed in degrees, between 0.0 and 360.0 degrees,\n * exclusive. If set to 0 or 360, the knob disappears.\n *\n * @example Suppose the compass were to be used to control a photosphere of an image that is 1000\n * x 500, and the window size is 500 x 500, that would mean the FOV is 500 / 1000 * 360 =\n * 180 degrees.\n */\n knobLength?: number\n\n /**\n * Radius of the compass.\n */\n radius?: number\n\n /**\n * The thickness of the knob, which is equivalent to the `stroke-width` of the `<path>` element.\n * Note that this overwrites the `stroke-width` set inside `knobCSS`.\n */\n knobThickness?: number\n\n /**\n * CSS of the knob, which is a `<path>` element.\n */\n knobCSS?: CSSProp<any>\n\n /**\n * The thickness of the circular track, which is equivalent to the `stroke-width` of the\n * `<circle>` element. Note that this overwrites the `stroke-width` set inside `trackCSS`.\n */\n trackThickness?: number\n\n /**\n * CSS of the track, which is a `<circle>` element.\n */\n trackCSS?: CSSProp<any>\n}\n\nfunction polarToCartesian(centerX: number, centerY: number, radius: number, angleInDegrees: number) {\n const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0\n\n return {\n x: centerX + (radius * Math.cos(angleInRadians)),\n y: centerY + (radius * Math.sin(angleInRadians)),\n }\n}\n\nfunction arcPath(x: number, y: number, radius: number, startAngle: number, endAngle: number) {\n const start = polarToCartesian(x, y, radius, endAngle)\n const end = polarToCartesian(x, y, radius, startAngle)\n const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1'\n const d = [\n 'M', start.x, start.y,\n 'A', radius, radius, 0, largeArcFlag, 0, end.x, end.y,\n ]\n\n return d.join(' ')\n}\n\n/**\n * A circular dial with a knob and a track.\n */\nexport default function Dial({\n id,\n className,\n style,\n angle = 0,\n radius = 50,\n knobLength = 30,\n knobThickness = 10,\n knobCSS,\n trackThickness = 2,\n trackCSS,\n}: Props) {\n const diameter = radius * 2\n const clampedKnobAngle = Math.max(0, Math.min(360, knobLength))\n\n return (\n <StyledRoot id={id} className={className} style={{ ...style, width: `${diameter}px`, height: `${diameter}px` }}>\n <StyledTrack>\n <svg width={diameter} height={diameter} viewBox={`0 0 ${diameter} ${diameter}`}>\n <StyledTrackCircle\n cx={radius}\n cy={radius}\n r={radius - trackThickness / 2}\n css={trackCSS}\n strokeWidth={trackThickness}\n />\n </svg>\n </StyledTrack>\n <StyledKnob style={{ transform: `rotate(${(angle + 360) % 360}deg)` }}>\n <svg viewBox={`0 0 ${diameter} ${diameter}`} xmlns='http://www.w3.org/2000/svg'>\n <StyledKnobPath css={knobCSS} strokeWidth={knobThickness} d={arcPath(radius, radius, radius - knobThickness / 2 - (trackThickness - knobThickness) / 2, -clampedKnobAngle / 2, clampedKnobAngle / 2)}/>\n </svg>\n </StyledKnob>\n </StyledRoot>\n )\n}\n\nconst StyledTrack = styled.div`\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n`\n\nconst StyledTrackCircle = styled.circle`\n stroke-dasharray: 4;\n stroke: #fff;\n ${props => props.css}\n`\n\nconst StyledKnob = styled.div`\n background-position: center;\n background-repeat: no-repeat;\n background-size: 100%;\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n\n svg {\n overflow: visible;\n position: absolute;\n right: 0;\n top: 0;\n }\n`\n\nconst StyledKnobPath = styled.path`\n stroke: #fff;\n ${props => props.css}\n`\n\nconst StyledRoot = styled.div`\n box-sizing: border-box;\n display: block;\n`\n"]}
package/lib/Dropdown.d.ts CHANGED
@@ -8,33 +8,113 @@ export declare type ButtonCSSProps = Readonly<{
8
8
  borderThickness: number;
9
9
  isActive: boolean;
10
10
  }>;
11
+ /**
12
+ * Type constraint of the data passed to each item in the component.
13
+ */
11
14
  export declare type DataProps<T = Record<string, never>> = T & {
12
15
  label?: string;
13
16
  };
17
+ /**
18
+ * Interface defining the props of the item component type to be provided to the
19
+ * component. The data type is generic.
20
+ */
14
21
  export declare type ItemComponentProps<T = Record<string, never>> = ListItemComponentProps<DataProps<T>>;
15
22
  export interface Props<T = Record<string, never>> {
23
+ /**
24
+ * Class attribute to the root element.
25
+ */
16
26
  className?: string;
27
+ /**
28
+ * Inline style attribute to the element.
29
+ */
17
30
  style?: CSSProperties;
31
+ /**
32
+ * Data of every item in the component. This is used to generate individual
33
+ * menu items. Data type is generic.
34
+ */
18
35
  data: DataProps<T>[];
36
+ /**
37
+ * Indicates if the component is inverted (i.e. "dropup" instead of dropdown).
38
+ * Supports all orientations.
39
+ */
19
40
  isInverted?: boolean;
41
+ /**
42
+ * Indicates if items can be toggled, i.e. they can be deselected if selected
43
+ * again.
44
+ */
20
45
  isTogglable?: boolean;
46
+ /**
47
+ * Thickness of the border (in pixels) of every item and the dropdown button
48
+ * itself. 0 indicates no borders.
49
+ */
21
50
  borderThickness?: number;
51
+ /**
52
+ * The index of the default selected item.
53
+ */
22
54
  defaultSelectedItemIndex?: number;
55
+ /**
56
+ * Length (in pixels) of each item. This does not apply to the dropdown button
57
+ * itself. Length refers to the height in vertical orientation and width in
58
+ * horizontal orientation.
59
+ */
23
60
  itemLength?: number;
61
+ /**
62
+ * Padding (in pixels) of each item.
63
+ */
24
64
  itemPadding?: number;
65
+ /**
66
+ * Maximum number of items that are viside when the component expands. When a
67
+ * value greater than or equal to 0 is specified, only that number of items
68
+ * will be visible at a time, and a scrollbar will appear to scroll to
69
+ * remaining items. Any value less than 0 indicates that all items will be
70
+ * visible when the component expands.
71
+ */
25
72
  maxVisibleItems?: number;
73
+ /**
74
+ * Orientation of the component.
75
+ */
26
76
  orientation?: Orientation;
77
+ /**
78
+ * Color of the border of every item and the dropdown button itself.
79
+ */
27
80
  borderColor?: string;
81
+ /**
82
+ * The label to appear on the dropdown button when no items are selected.
83
+ */
28
84
  defaultLabel?: string;
85
+ /**
86
+ * SVG markup to be put in the dropdown button as the expand icon.
87
+ */
29
88
  expandIconSvg?: string;
89
+ /**
90
+ * React component type to be used for generating items inside the component.
91
+ */
30
92
  itemComponentType: ComponentType<ItemComponentProps<T>>;
93
+ /**
94
+ * Handler invoked whenever the selected index changes.
95
+ */
31
96
  onIndexChange?: (index: number) => void;
97
+ /**
98
+ * Additional CSS to be provided to the dropdown button.
99
+ */
32
100
  buttonCSS?: ExtendedCSSFunction<ButtonCSSProps>;
33
101
  }
34
102
  export interface State {
103
+ /**
104
+ * Index of the currently selected item. Any value less than 0 indicates that
105
+ * no item is selected.
106
+ */
35
107
  selectedItemIndex: number;
108
+ /**
109
+ * Indicates if the dropdown menu is collapsed.
110
+ */
36
111
  isCollapsed: boolean;
37
112
  }
113
+ /**
114
+ * A dropdown menu component that is invertible (i.e. can "dropup" instead) and
115
+ * supports both horizontal and vertical orientations. Provide data and item
116
+ * component type to this component to automatically generate menu items.
117
+ */
38
118
  export default class Dropdown<T = Record<string, never>> extends PureComponent<Props<T>, State> {
39
119
  nodeRefs: {
40
120
  root: React.RefObject<HTMLDivElement>;
@@ -45,10 +125,38 @@ export default class Dropdown<T = Record<string, never>> extends PureComponent<P
45
125
  componentWillUnmount(): void;
46
126
  componentDidUpdate(prevProps: Props<T>, prevState: State): void;
47
127
  render(): JSX.Element;
128
+ /**
129
+ * Indicates if the item at the specified index is selected.
130
+ *
131
+ * @param index - The index of the item.
132
+ *
133
+ * @returns `true` if the item at the specified index is selected, `false`
134
+ * otherwise.
135
+ */
48
136
  isItemSelectedAt(index: number): boolean;
137
+ /**
138
+ * Selects the item at the specified index.
139
+ *
140
+ * @param index - The index of the item to select.
141
+ */
49
142
  selectItemAt(index: number): void;
143
+ /**
144
+ * Expands the menu, revealing its items.
145
+ */
50
146
  expand(): void;
147
+ /**
148
+ * Collapses the menu, concealing its items.
149
+ */
51
150
  collapse(): void;
151
+ /**
152
+ * Toggles the visibility of the menu.
153
+ */
52
154
  toggle(): void;
155
+ /**
156
+ * Handler invoked when click input is detected outside of the root element
157
+ * of the component.
158
+ *
159
+ * @param event - The MouseEvent passed to the handler.
160
+ */
53
161
  private onClickOutside;
54
162
  }