From 63fc0b4e26029170b26820336029f252f92e6b32 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 1 Oct 2020 15:18:52 -0500 Subject: [PATCH] Accordion: refactor --- app/soapbox/features/soapbox_config/index.js | 4 +- .../features/ui/components/accordion.js | 33 +++++----- app/styles/application.scss | 1 + app/styles/basics.scss | 44 ------------- app/styles/components/accordion.scss | 63 +++++++++++++++++++ app/styles/forms.scss | 24 ++++--- 6 files changed, 97 insertions(+), 72 deletions(-) create mode 100644 app/styles/components/accordion.scss diff --git a/app/soapbox/features/soapbox_config/index.js b/app/soapbox/features/soapbox_config/index.js index 0fa43392a..505471751 100644 --- a/app/soapbox/features/soapbox_config/index.js +++ b/app/soapbox/features/soapbox_config/index.js @@ -349,7 +349,7 @@ class SoapboxConfig extends ImmutablePureComponent { + content={(
- } + )} />
diff --git a/app/soapbox/features/ui/components/accordion.js b/app/soapbox/features/ui/components/accordion.js index a06442ce6..1f372f002 100644 --- a/app/soapbox/features/ui/components/accordion.js +++ b/app/soapbox/features/ui/components/accordion.js @@ -1,19 +1,17 @@ import React from 'react'; import PropTypes from 'prop-types'; import { defineMessages, injectIntl } from 'react-intl'; -import IconButton from 'soapbox/components/icon_button'; import classNames from 'classnames'; const messages = defineMessages({ - collapse: { id: 'accordion.collapse', defaultMessage: 'Collapse accordion' }, - expand: { id: 'accordion.expand', defaultMessage: 'Expand accordion' }, + collapse: { id: 'accordion.collapse', defaultMessage: 'Collapse' }, + expand: { id: 'accordion.expand', defaultMessage: 'Expand' }, }); - export default @injectIntl class Accordion extends React.PureComponent { static propTypes = { - headline: PropTypes.string, + headline: PropTypes.string.isRequired, content: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), intl: PropTypes.object.isRequired, }; @@ -22,8 +20,9 @@ export default @injectIntl class Accordion extends React.PureComponent { expanded: false, } - handleToggleAccordion = () => { + handleToggleAccordion = (e) => { this.setState({ expanded: !this.state.expanded }); + e.preventDefault(); } render() { @@ -31,20 +30,16 @@ export default @injectIntl class Accordion extends React.PureComponent { const { expanded } = this.state; return ( -
- {headline &&
{headline} - -
} -
+ +
{content}
diff --git a/app/styles/application.scss b/app/styles/application.scss index 2e00c036b..d5158761b 100644 --- a/app/styles/application.scss +++ b/app/styles/application.scss @@ -71,6 +71,7 @@ @import 'components/filters'; @import 'components/mfa_form'; @import 'components/snackbar'; +@import 'components/accordion'; // Holiday @import 'holiday/halloween'; diff --git a/app/styles/basics.scss b/app/styles/basics.scss index 9f42af2d7..621c7bbb2 100644 --- a/app/styles/basics.scss +++ b/app/styles/basics.scss @@ -159,50 +159,6 @@ body { color: #ffffff; } -.explanation-box, -.accordion { - color: var(--primary-text-color); - padding: 15px 20px; - font-size: 14px; - background-color: var(--brand-color--faint); - margin: 5px 20px; - border-radius: 8px; - - &__title { - font-weight: bold; - font-size: 16px; - } - - &__explanation { - margin-top: 1em; - } - - a { - color: var(--brand-color--hicontrast); - text-decoration: underline; - - &:hover { - text-decoration: none; - } - } -} - -.accordion { - margin: 0; - - .accordion_content { - transition-duration: 0.2s; - - &.expanded { - display: block; - } - - &.closed { - display: none; - } - } -} - noscript { text-align: center; diff --git a/app/styles/components/accordion.scss b/app/styles/components/accordion.scss new file mode 100644 index 000000000..366ceb8ea --- /dev/null +++ b/app/styles/components/accordion.scss @@ -0,0 +1,63 @@ +.explanation-box { + margin: 5px 20px; +} + +.explanation-box, +.accordion { + color: var(--primary-text-color); + padding: 15px 20px; + font-size: 14px; + background-color: var(--brand-color--faint); + border-radius: 8px; + margin: 0; + + &__title { + font-weight: bold !important; + font-size: 16px !important; + background: transparent !important; + padding: 0 !important; + margin: 0 !important; + text-transform: none !important; + text-align: left !important; + display: flex !important; + + &::after { + content: ''; + display: block; + font-family: ForkAwesome; + font-size: 20px; + padding-left: 10px; + margin-left: auto; + } + } + + &__content { + height: 0; + overflow: hidden; + } + + &--expanded &__title { + margin-bottom: 10px !important; + + &::after { + content: ''; + } + } + + &--expanded &__content { + height: auto; + } + + &__explanation { + margin-top: 1em; + } + + a { + color: var(--brand-color--hicontrast); + text-decoration: underline; + + &:hover { + text-decoration: none; + } + } +} diff --git a/app/styles/forms.scss b/app/styles/forms.scss index b741d5642..8338f2af3 100644 --- a/app/styles/forms.scss +++ b/app/styles/forms.scss @@ -679,14 +679,24 @@ code { max-height: 100px; } -.code-editor textarea { - font-family: monospace; - white-space: pre; -} +.code-editor { + textarea { + font-family: monospace; + white-space: pre; + } -.code-editor--invalid textarea { - border-color: $error-red !important; - color: $error-red; + &--invalid textarea { + border-color: $error-red !important; + color: $error-red; + } + + .input { + margin-bottom: 0; + } + + .hint { + margin-top: 10px; + } } .input .row .fa-times-circle {