Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move button bar to bottom #955

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions administration/src/bp-modules/ButtonBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Card } from '@blueprintjs/core'
import styled from 'styled-components'

const ButtonBar = styled(Card)`
width: 100%;
padding: 15px;
background: #fafafa;
bottom: 0;
display: flex;
flex-direction: row;
justify-content: flex-end;
& button {
margin: 5px;
}
`

export default ButtonBar
98 changes: 59 additions & 39 deletions administration/src/bp-modules/cards/CreateCardsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
import { Button, Card, Tooltip } from '@blueprintjs/core'
import React, { useContext, useState } from 'react'
import { Button, Icon, Tooltip } from '@blueprintjs/core'
import { useContext, useRef, useState } from 'react'
import FlipMove from 'react-flip-move'
import styled from 'styled-components'

import { CardBlueprint } from '../../cards/CardBlueprint'
import { Region } from '../../generated/graphql'
import { ProjectConfigContext } from '../../project-configs/ProjectConfigContext'
import useBlockNavigation from '../../util/useBlockNavigation'
import AddEakButton from './AddEakButton'
import ButtonBar from '../ButtonBar'
import CreateCardForm from './CreateCardForm'

const ButtonBar = styled(({ stickyTop: number, ...rest }) => <Card {...rest} />)<{ stickyTop: number }>`
width: 100%;
padding: 15px;
background: #fafafa;
position: sticky;
z-index: 1;
top: ${props => props.stickyTop}px;
display: flex;
const FormsWrapper = styled(FlipMove)`
flex-wrap: wrap;
flex-grow: 1;
flex-direction: row;
justify-content: flex-end;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: center;
`

& button {
margin: 5px;
const AddButton = styled(Button)`
cursor: pointer;
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
padding: 10px;
justify-content: center;
align-items: center;
transition: 0.2s background;
background: white;

:hover {
background: #f0f0f0;
}
`

const FormsWrapper = styled(FlipMove)`
const Scrollable = styled.div`
display: flex;
flex-grow: 1;
flex-direction: column;
flex-basis: 0;
padding: 10px;
width: 100%;
z-index: 0;
flex-grow: 1;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: center;
overflow: auto;
`

const FormColumn = styled.div`
Expand All @@ -52,12 +62,18 @@ interface Props {

const CreateCardsForm = (props: Props) => {
const { cardBlueprints, setCardBlueprints, region } = props
const bottomRef = useRef<HTMLDivElement>(null)
const projectConfig = useContext(ProjectConfigContext)
const [isModified, setModified] = useState(false)

const scrollToBottom = () => {
if (bottomRef.current) bottomRef.current.scrollIntoView({ behavior: 'smooth' })
}

const addForm = () => {
setCardBlueprints([...cardBlueprints, projectConfig.createEmptyCard(region)])
setModified(true)
scrollToBottom()
}
const removeCardBlueprint = (oldBlueprint: CardBlueprint) => {
setCardBlueprints(cardBlueprints.filter(blueprint => blueprint !== oldBlueprint))
Expand All @@ -74,7 +90,28 @@ const CreateCardsForm = (props: Props) => {

return (
<>
<ButtonBar stickyTop={0}>
<Scrollable>
<FormsWrapper onFinish={scrollToBottom}>
{cardBlueprints.map(blueprint => (
<FormColumn key={blueprint.id}>
<CreateCardForm
cardBlueprint={blueprint}
onRemove={() => removeCardBlueprint(blueprint)}
onUpdate={() => {
notifyUpdate()
}}
/>
</FormColumn>
))}
<FormColumn key='AddButton'>
<AddButton icon={<Icon style={{ margin: 10 }} icon={'add'} iconSize={20} />} onClick={addForm}>
Karte hinzufügen
</AddButton>
</FormColumn>
</FormsWrapper>
<div ref={bottomRef} />
</Scrollable>
<ButtonBar>
<Tooltip>
<Button
icon='export'
Expand All @@ -87,23 +124,6 @@ const CreateCardsForm = (props: Props) => {
{cardBlueprints.length === 0 && 'Legen Sie zunächst eine Karte an.'}
</Tooltip>
</ButtonBar>
{/* @ts-ignore */}
<FormsWrapper>
{cardBlueprints.map(blueprint => (
<FormColumn key={blueprint.id}>
<CreateCardForm
cardBlueprint={blueprint}
onRemove={() => removeCardBlueprint(blueprint)}
onUpdate={() => {
notifyUpdate()
}}
/>
</FormColumn>
))}
<FormColumn key='AddButton'>
<AddEakButton onClick={addForm} />
</FormColumn>
</FormsWrapper>
</>
)
}
Expand Down
42 changes: 14 additions & 28 deletions administration/src/bp-modules/regions/RegionOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Card, H3, TextArea } from '@blueprintjs/core'
import { Button, H3, TextArea } from '@blueprintjs/core'
import { Tooltip2 } from '@blueprintjs/popover2'
import React, { ReactElement, useState } from 'react'
import styled from 'styled-components'
Expand All @@ -7,6 +7,7 @@ import defaultErrorMap from '../../errors/DefaultErrorMap'
import getMessageFromApolloError from '../../errors/getMessageFromApolloError'
import { GraphQlExceptionCode, useUpdateDataPolicyMutation } from '../../generated/graphql'
import { useAppToaster } from '../AppToaster'
import ButtonBar from '../ButtonBar'

const Content = styled.div`
padding: 0 6rem;
Expand All @@ -23,21 +24,6 @@ const Label = styled(H3)`
text-align: center;
margin: 15px;
`
const ButtonBar = styled(({ stickyTop: number, ...rest }) => <Card {...rest} />)<{ stickyTop: number }>`
width: 100%;
padding: 15px;
background: #fafafa;
position: sticky;
z-index: 1;
top: ${props => props.stickyTop}px;
display: flex;
flex-direction: row;
justify-content: flex-end;

& button {
margin: 5px;
}
`

const CharCounter = styled.span<{ $hasError: boolean }>`
text-align: center;
Expand Down Expand Up @@ -74,18 +60,6 @@ const RegionOverview = ({ dataPrivacyPolicy, regionId }: RegionOverviewProps): R

return (
<>
<ButtonBar stickyTop={0}>
<Tooltip2 disabled={!maxCharsExceeded} content={errorMessage}>
<Button
disabled={maxCharsExceeded}
icon='floppy-disk'
text='Speichern'
intent='success'
onClick={onSave}
loading={loading}
/>
</Tooltip2>
</ButtonBar>
<Content>
<Label>Datenschutzerklärung</Label>
<TextArea
Expand All @@ -100,6 +74,18 @@ const RegionOverview = ({ dataPrivacyPolicy, regionId }: RegionOverviewProps): R
{dataPrivacyText.length}/{MAX_CHARS}
</CharCounter>
</Content>
<ButtonBar>
<Tooltip2 disabled={!maxCharsExceeded} content={errorMessage}>
<Button
disabled={maxCharsExceeded}
icon='floppy-disk'
text='Speichern'
intent='success'
onClick={onSave}
loading={loading}
/>
</Tooltip2>
</ButtonBar>
</>
)
}
Expand Down