summaryrefslogtreecommitdiff
path: root/src/components/Selection.js
diff options
context:
space:
mode:
authorHaishan <[email protected]>2019-04-21 00:05:44 +0800
committerHaishan <[email protected]>2019-04-21 21:58:33 +0800
commit882b168082ddbcbe7991a71a09944f1a60084fc3 (patch)
treed12345be635943537042a929aed8376ae4480324 /src/components/Selection.js
parenteda2501b1d68c6f82a4a824ffe12caf5be7b33f2 (diff)
squash: feat(config): add options to select traffic chart style
Diffstat (limited to 'src/components/Selection.js')
-rw-r--r--src/components/Selection.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/components/Selection.js b/src/components/Selection.js
new file mode 100644
index 0000000..12816f9
--- /dev/null
+++ b/src/components/Selection.js
@@ -0,0 +1,61 @@
+import React from 'react';
+import { func, array, number } from 'prop-types';
+import cx from 'classnames';
+
+import s from './Selection.module.css';
+
+export default function Selection({
+ OptionComponent,
+ optionPropsList,
+ selectedIndex,
+ onChange
+}) {
+ return (
+ // TODO a11y
+ // tabIndex="0"
+ <div className={s.root}>
+ {optionPropsList.map((props, idx) => {
+ const className = cx(s.item, { [s.itemActive]: idx === selectedIndex });
+ return (
+ <div
+ key={idx}
+ className={className}
+ onClick={ev => {
+ ev.preventDefault();
+ if (idx !== selectedIndex) {
+ onChange(idx);
+ }
+ }}
+ >
+ <OptionComponent {...props} />
+ </div>
+ );
+ })}
+ </div>
+ );
+}
+
+Selection.propTypes = {
+ OptionComponent: func,
+ optionPropsList: array,
+ selectedIndex: number,
+ onChange: func
+};
+
+// for test
+export function Option({ title }) {
+ // eslint-disable-next-line no-undef
+ if (__DEV__) {
+ return (
+ <div
+ style={{
+ width: 100,
+ height: 60,
+ backgroundColor: '#eee'
+ }}
+ >
+ {title}
+ </div>
+ );
+ }
+}