From 017cdf060fd0dd3f60406c66819d69dfac2f4e8b Mon Sep 17 00:00:00 2001 From: Stephen Ramthun Date: Wed, 31 Jul 2019 09:10:43 +0200 Subject: [PATCH] Dynamic textarea (#50) * Add dynamically sized textarea * Fix layout of uenigheter --- .../pages/Oppsummering/Innrapportering.jsx | 3 +- .../pages/Oppsummering/Innrapportering.less | 31 +++++++++- .../pages/Oppsummering/Oppsummering.jsx | 2 +- .../{Oppsummering.css => Oppsummering.less} | 19 +----- src/components/widgets/Bolk/ListeItemBolk.css | 3 +- src/components/widgets/DynamicTextarea.jsx | 58 +++++++++++++++++++ src/components/widgets/Uenigboks.css | 19 +++--- src/components/widgets/Uenigboks.jsx | 19 +++--- src/hooks/useKeyboard.js | 8 +-- 9 files changed, 108 insertions(+), 54 deletions(-) rename src/components/pages/Oppsummering/{Oppsummering.css => Oppsummering.less} (51%) create mode 100644 src/components/widgets/DynamicTextarea.jsx diff --git a/src/components/pages/Oppsummering/Innrapportering.jsx b/src/components/pages/Oppsummering/Innrapportering.jsx index 1c172247e..2693a794a 100644 --- a/src/components/pages/Oppsummering/Innrapportering.jsx +++ b/src/components/pages/Oppsummering/Innrapportering.jsx @@ -45,7 +45,8 @@ const Innrapportering = withBehandlingContext(({ behandling }) => { <> {innrapportering.uenigheter.map((uenighet, i) => ( - {uenighet.label} - {uenighet.value} + {uenighet.label}: + {uenighet.value} ))} {innrapportering.hasSendt ? ( diff --git a/src/components/pages/Oppsummering/Innrapportering.less b/src/components/pages/Oppsummering/Innrapportering.less index 64a3349c9..001b37cb7 100644 --- a/src/components/pages/Oppsummering/Innrapportering.less +++ b/src/components/pages/Oppsummering/Innrapportering.less @@ -1,11 +1,38 @@ -@sendtColor: #38a161; - .Innrapportering.panel { + display: flex; + flex-direction: column; + + > .typo-normal { + display: flex; + align-items: flex-start; + + > * { + margin-left: 0.5rem; + } + } + + > .typo-normal:not(:last-child) { + margin-bottom: 0.5rem; + } + + .typo-normal span:first-child { + @width: 15rem; + min-width: @width; + max-width: @width; + } + + .typo-normal span:last-child { + font-style: italic; + min-width: 15rem; + } + .knapp { width: max-content; display: flex; + margin-top: 1rem; &.sendt { + @sendtColor: #38a161; border-color: @sendtColor; color: @sendtColor; } diff --git a/src/components/pages/Oppsummering/Oppsummering.jsx b/src/components/pages/Oppsummering/Oppsummering.jsx index 75aa03036..63659c728 100644 --- a/src/components/pages/Oppsummering/Oppsummering.jsx +++ b/src/components/pages/Oppsummering/Oppsummering.jsx @@ -8,7 +8,7 @@ import ListeItem from '../../widgets/ListeItem'; import ListeSeparator from '../../widgets/ListeSeparator'; import Navigasjonsknapper from '../../widgets/Navigasjonsknapper'; import Innrapportering from './Innrapportering'; -import './Oppsummering.css'; +import './Oppsummering.less'; const Oppsummering = withBehandlingContext(({ behandling }) => (
diff --git a/src/components/pages/Oppsummering/Oppsummering.css b/src/components/pages/Oppsummering/Oppsummering.less similarity index 51% rename from src/components/pages/Oppsummering/Oppsummering.css rename to src/components/pages/Oppsummering/Oppsummering.less index 3e7f690eb..fa8f94ad5 100644 --- a/src/components/pages/Oppsummering/Oppsummering.css +++ b/src/components/pages/Oppsummering/Oppsummering.less @@ -20,21 +20,4 @@ .Oppsummering + .Navigasjonsknapper { margin-left: 1rem; -} - -.Oppsummering__right-col .panel { - display: flex; - flex-direction: column; -} - -.Oppsummering__right-col .panel > .typo-normal:not(:last-child) { - margin-bottom: 0.5rem; -} - -.Oppsummering__right-col .panel .typo-normal span { - font-style: italic; -} - -.Oppsummering__right-col .panel .knapp { - margin-top: 1rem; -} +} \ No newline at end of file diff --git a/src/components/widgets/Bolk/ListeItemBolk.css b/src/components/widgets/Bolk/ListeItemBolk.css index c74a83b8b..f1a5013c6 100644 --- a/src/components/widgets/Bolk/ListeItemBolk.css +++ b/src/components/widgets/Bolk/ListeItemBolk.css @@ -1,13 +1,14 @@ .ListeItemBolk { display: flex; flex-wrap: nowrap; - align-items: center; + align-items: flex-start; } .ListeItemBolk .ListeItem { flex: 1; display: flex; align-items: center; + margin-top: 0.85rem; max-width: 18rem; min-width: 18rem; } diff --git a/src/components/widgets/DynamicTextarea.jsx b/src/components/widgets/DynamicTextarea.jsx new file mode 100644 index 000000000..b0c7cdf82 --- /dev/null +++ b/src/components/widgets/DynamicTextarea.jsx @@ -0,0 +1,58 @@ +import React, { useEffect, useState } from 'react'; +import PropTypes from 'prop-types'; + +const lineHeight = 22; + +const DynamicTextarea = ({ + name, + value, + placeholder, + maxCharacters, + disabled, + forwardedRef, + ...rest +}) => { + const [rows, setRows] = useState(1); + + useEffect(() => { + if (forwardedRef && forwardedRef.current) { + setRows(Math.floor(forwardedRef.current.scrollHeight / lineHeight)); + } + }, [value, forwardedRef]); + + return ( +