Skip to content

Commit

Permalink
Fix spacing in forms
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmar committed Oct 20, 2023
1 parent 1310862 commit 76190ee
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 66 deletions.
14 changes: 9 additions & 5 deletions www/src/components/account/CreateGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode, useCallback, useContext, useEffect, useState } from 'react'
import { Box } from 'grommet'
import { Button, Modal, ValidatedInput } from '@pluralsh/design-system'
import { useTheme } from 'styled-components'

import { appendConnection, updateCache } from '../../utils/graphql'
import { GqlError } from '../utils/Alert'
Expand All @@ -10,6 +10,7 @@ import SubscriptionContext from '../../contexts/SubscriptionContext'
import BillingFeatureBlockModal from './billing/BillingFeatureBlockModal'

export function CreateGroup({ q }: any) {
const theme = useTheme()
const { availableFeatures } = useContext(SubscriptionContext)
const isAvailable = !!availableFeatures?.userManagement
const [createModalVisible, setCreateModalVisible] = useState(false)
Expand Down Expand Up @@ -82,9 +83,12 @@ export function CreateGroup({ q }: any) {
</>
}
>
<Box
width="50vw"
gap="small"
<div
css={{
display: 'flex',
flexDirection: 'column',
gap: theme.spacing.medium,
}}
>
{errorMsg}
<ValidatedInput
Expand All @@ -97,7 +101,7 @@ export function CreateGroup({ q }: any) {
value={description}
onChange={({ target: { value } }) => setDescription(value)}
/>
</Box>
</div>
</Modal>
<BillingFeatureBlockModal
open={blockModalVisible}
Expand Down
2 changes: 1 addition & 1 deletion www/src/components/account/CreateServiceAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function ServiceAccountForm({
return (
<Box
fill
gap="small"
gap="medium"
{...box}
>
{error && (
Expand Down
1 change: 0 additions & 1 deletion www/src/components/account/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function GroupMember({ user, group, first, last, edit }: any) {
return (
<ListItem
flex={false}
background="fill-two"
first={first}
last={last}
>
Expand Down
16 changes: 10 additions & 6 deletions www/src/components/account/Role.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { Box } from 'grommet'
import { ValidatedInput } from '@pluralsh/design-system'
import { ValidatedInput, theme } from '@pluralsh/design-system'

Check failure on line 1 in www/src/components/account/Role.tsx

View workflow job for this annotation

GitHub Actions / Lint

'theme' is defined but never used. Allowed unused vars must match /^_/u
import { useState } from 'react'

import { BindingInput } from './Typeaheads'

Check failure on line 4 in www/src/components/account/Role.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import { useTheme } from 'styled-components'

Check failure on line 5 in www/src/components/account/Role.tsx

View workflow job for this annotation

GitHub Actions / Lint

`styled-components` import should occur before import of `./Typeaheads`

export function GeneralAttributes({
attributes,
setAttributes,
bindings,
setBindings,
}: any) {
const theme = useTheme()
const [repositories, setRepositories] = useState(
attributes.repositories?.join(', ')
)

return (
<Box
flex={false}
gap="small"
<div
css={{
display: 'flex',
flexDirection: 'column',
rowGap: theme.spacing.medium,
}}
>
<ValidatedInput
label="Name"
Expand Down Expand Up @@ -68,6 +72,6 @@ export function GeneralAttributes({
)
}
/>
</Box>
</div>
)
}
99 changes: 74 additions & 25 deletions www/src/components/account/RoleForm.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Box } from 'grommet'
import { Span } from 'honorable'
import { Tab, TabList, TabPanel, Switch } from '@pluralsh/design-system'

Check failure on line 1 in www/src/components/account/RoleForm.tsx

View workflow job for this annotation

GitHub Actions / Lint

Member 'Switch' of the import declaration should be sorted alphabetically
import { useCallback, useRef, useState } from 'react'

import { ListItem } from '../profile/ListItem'
import { GqlError } from '../utils/Alert'

import { PermissionTypes } from './types'

import { GeneralAttributes } from './Role'

Check failure on line 8 in www/src/components/account/RoleForm.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import { useTheme } from 'styled-components'

Check failure on line 9 in www/src/components/account/RoleForm.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import { List, ListItem } from '../utils/List'

function PermissionToggle({
permission,
Expand All @@ -18,6 +17,7 @@ function PermissionToggle({
first,
last,
}: any) {
const theme = useTheme()
const toggle = useCallback(
(enable) => {
if (enable) {
Expand All @@ -41,12 +41,34 @@ function PermissionToggle({
<ListItem
first={first}
last={last}
background="fill-two"
>
<Box fill="horizontal">
<Span fontWeight={500}>{permission.toLowerCase()}</Span>
<Span color="text-light">{description}</Span>
</Box>
<div
css={{
display: 'flex',
flexDirection: 'column',
width: '100%',
}}
>
<h4
className="stuff"
css={{
...theme.partials.text.body1Bold,
margin: 0,
}}
>
{permission.toLowerCase()}
</h4>
<p
css={{
...theme.partials.text.body2,
color: theme.colors['text-light'],
margin: 0,
}}
color="text-light"
>
{description}
</p>
</div>
<Switch
checked={!!attributes.permissions.find((perm) => perm === permission)}
onChange={(checked) => toggle(checked)}
Expand All @@ -61,24 +83,31 @@ const TABS = {
}

export function RoleForm({
// eslint-disable-next-line
error,
attributes,
setAttributes,
bindings,
setBindings,
...box
}): any {
}: {
error: any
attributes: any
setAttributes: any
bindings: any
setBindings: any
}) {
const theme = useTheme()
const [view, setView] = useState('General')
const permissions = Object.entries(PermissionTypes)
const len = permissions.length
const tabStateRef = useRef<any>(null)

return (
<Box
flex={false}
gap="small"
{...box}
<div
css={{
display: 'flex',
flexDirection: 'column',
gap: theme.spacing.medium,
}}
>
{error && (
<GqlError
Expand Down Expand Up @@ -108,14 +137,34 @@ export function RoleForm({
/>
)}
{view === 'Permissions' && (
<Box gap="small">
<Box>
<Span fontWeight="bold">Permissions</Span>
<Span>
<div
css={{
display: 'flex',
flexDirection: 'column',
gap: theme.spacing.small,
}}
>
<div
css={{
display: 'flex',
flexDirection: 'column',
gap: theme.spacing.xxsmall,
}}
>
<h3 css={{ ...theme.partials.text.body1Bold, margin: 0 }}>
Permissions
</h3>
<p
css={{
...theme.partials.text.body2,
margin: 0,
color: theme.colors['text-light'],
}}
>
Grant permissions to all users and groups bound to this role
</Span>
</Box>
<Box>
</p>
</div>
<List hue="lighter">
{permissions.map(([perm, description], i) => (
<PermissionToggle
key={perm}
Expand All @@ -127,10 +176,10 @@ export function RoleForm({
last={i === len - 1}
/>
))}
</Box>
</Box>
</List>
</div>
)}
</TabPanel>
</Box>
</div>
)
}
65 changes: 37 additions & 28 deletions www/src/components/profile/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
import { useTheme } from 'styled-components'
import { Box } from 'grommet'
import { ComponentProps, ReactNode } from 'react'
import styled, { useTheme } from 'styled-components'

export function ListItem({ first, last, children, background }: any) {
const theme = useTheme()
const ListItemSC = styled.div<{ $first: boolean; $last: boolean }>(
({ theme, $first: first, $last: last }) => {
const BORDER_RADIUS = theme.borderRadiuses.large

return {
display: 'flex',
flex: '0 0',
backgroundColor: theme.colors['fill-one'],
alignItems: 'center',
padding: 16,
borderTop: first ? theme.borders.default : undefined,
borderBottom: theme.borders.default,
borderLeft: theme.borders.default,
borderRight: theme.borders.default,
borderBottomRightRadius: last ? BORDER_RADIUS : undefined,
borderBottomLeftRadius: last ? BORDER_RADIUS : undefined,
borderTopRightRadius: first ? BORDER_RADIUS : undefined,
borderTopLeftRadius: first ? BORDER_RADIUS : undefined,
}
}
)

const BORDER_RADIUS = `${theme.borderRadiuses.large}px`
const r = (corner) => ({ corner, size: BORDER_RADIUS })
export function ListItem({
first,
last,
...props
}: {
first: boolean
last: boolean
} & ComponentProps<typeof ListItemSC>) {
const theme = useTheme()

return (
<Box
flex={false}
background={{ color: background || 'fill-one' }}
direction="row"
align="center"
pad="16px"
border={
first ? { side: 'all' } : [{ side: 'vertical' }, { side: 'bottom' }]
}
// @ts-expect-error
round={
first && last
? BORDER_RADIUS
: first
? r('top')
: last
? r('bottom')
: null
}
>
{children}
</Box>
<ListItemSC
$first={first}
$last={last}
{...props}
/>
)
}

0 comments on commit 76190ee

Please sign in to comment.