about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/notifications/components/pill_bar_button.js
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-03-24 10:14:42 +0100
committerGitHub <noreply@github.com>2021-03-24 10:14:42 +0100
commitd7c1c41859549212a6d34ad869fded16acc17b48 (patch)
tree162079c55cfe182fc801fe5969469cf6fda9082c /app/javascript/flavours/glitch/features/notifications/components/pill_bar_button.js
parentc7f04961b6dcb1b7e12136deadcf65076c130c40 (diff)
parent2bb573d021d53a31efd299763cd55d342d4da307 (diff)
Merge pull request #1515 from ClearlyClaire/glitch-soc/features/notifications-design
Change notification settings UI to be more compact
Diffstat (limited to 'app/javascript/flavours/glitch/features/notifications/components/pill_bar_button.js')
-rw-r--r--app/javascript/flavours/glitch/features/notifications/components/pill_bar_button.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/features/notifications/components/pill_bar_button.js b/app/javascript/flavours/glitch/features/notifications/components/pill_bar_button.js
new file mode 100644
index 000000000..223b7f75f
--- /dev/null
+++ b/app/javascript/flavours/glitch/features/notifications/components/pill_bar_button.js
@@ -0,0 +1,41 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import ImmutablePropTypes from 'react-immutable-proptypes';
+import classNames from 'classnames'
+
+export default class PillBarButton extends React.PureComponent {
+
+  static propTypes = {
+    prefix: PropTypes.string,
+    settings: ImmutablePropTypes.map.isRequired,
+    settingPath: PropTypes.array.isRequired,
+    label: PropTypes.node.isRequired,
+    onChange: PropTypes.func.isRequired,
+    disabled: PropTypes.bool,
+  }
+
+  onChange = () => {
+    const { settings, settingPath } = this.props;
+    this.props.onChange(settingPath, !settings.getIn(settingPath));
+  }
+
+  render () {
+    const { prefix, settings, settingPath, label, disabled } = this.props;
+    const id = ['setting-pillbar-button', prefix, ...settingPath].filter(Boolean).join('-');
+    const active = settings.getIn(settingPath);
+
+    return (
+      <button
+        key={id}
+        id={id}
+        className={classNames('pillbar-button', { active })}
+        disabled={disabled}
+        onClick={this.onChange}
+        aria-pressed={active}
+      >
+        {label}
+      </button>
+    );
+  }
+
+}