Skip to content

Commit

Permalink
feat: fixes colors
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed May 29, 2024
1 parent 491002b commit 88bb564
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 12 deletions.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.13.1
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- hooks:
- id: commitizen
- id: commitizen-branch
stages:
- push
repo: https://github.com/commitizen-tools/commitizen
rev: v3.27.0
3 changes: 2 additions & 1 deletion app/frontend/Components/Button/CheckinButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link } from '@/Components'
import { type LinkProps } from '../Link'
import { CheckinIcon } from '@/Components/Icons'
import { Tooltip, useMantineTheme } from '@mantine/core'
import { useContrastingTextColor } from '@/lib/hooks'

interface CheckinButtonProps extends Omit<LinkProps, 'children'> {
href: string
Expand Down Expand Up @@ -38,7 +39,7 @@ const CheckinButton = ({ href, label, disabled, tooltipMessage, ...props }: Chec
aria-label={ usedLabel }
{ ...finalProps }
>
<CheckinIcon />
<CheckinIcon color={ useContrastingTextColor(checkinButtonColor) } />
</Link>
</Tooltip>
)
Expand Down
3 changes: 2 additions & 1 deletion app/frontend/Components/Button/CheckoutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link } from '@/Components'
import { type LinkProps } from '../Link'
import { CheckoutIcon } from '@/Components/Icons'
import { Tooltip, useMantineTheme } from '@mantine/core'
import { useContrastingTextColor } from '@/lib/hooks'

interface CheckoutButtonProps extends Omit<LinkProps, 'children'> {
href: string
Expand Down Expand Up @@ -31,7 +32,7 @@ const CheckoutButton = ({ href, label, disabled, tooltipMessage, ...props }: Che
aria-label={ usedLabel }
{ ...props }
>
<CheckoutIcon />
<CheckoutIcon color={ useContrastingTextColor(checkoutButtonColor) } />
</Link>
</Tooltip>
)
Expand Down
3 changes: 2 additions & 1 deletion app/frontend/Components/Button/DeleteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link, Tooltip } from '@/Components'
import { type LinkProps } from '../Link'
import { TrashIcon } from '@/Components/Icons'
import { useMantineTheme } from '@mantine/core'
import { useContrastingTextColor } from '@/lib/hooks'

interface DeleteButtonProps extends Omit<LinkProps, 'children'> {
label?: string
Expand All @@ -23,7 +24,7 @@ const DeleteButton = ({ href, label, tooltipMessage }: DeleteButtonProps) => {
color={ deleteButtonColor }
>
<Link as="button" href={ href } aria-label={ `Delete ${label}` }>
<TrashIcon />
<TrashIcon color={ useContrastingTextColor(deleteButtonColor) } />
</Link>
</Tooltip>
)
Expand Down
5 changes: 4 additions & 1 deletion app/frontend/Components/Button/EditButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link, Tooltip } from '@/Components'
import { EditIcon } from '@/Components/Icons'
import { LinkProps } from '../Link'
import { useMantineTheme } from '@mantine/core'
import { useContrastingTextColor } from '@/lib/hooks'

interface EditButtonProps extends Omit<LinkProps, 'children'> {
label?: string
Expand All @@ -22,7 +23,9 @@ const EditButton = ({ href, label }: EditButtonProps) => {
aria-label={ usedLabel }
color={ primaryColor }
>
<Link as="button" href={ href } aria-label={ `Edit ${label}` }><EditIcon /></Link>
<Link as="button" href={ href } aria-label={ `Edit ${label}` }>
<EditIcon color={ useContrastingTextColor(primaryColor) } />
</Link>
</Tooltip>
)
}
Expand Down
8 changes: 7 additions & 1 deletion app/frontend/Components/Form/Form.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export const fieldset = css`

export const dynamicInputItem = css`
.mantine-Paper-root {
background-color: ${vars.colors.gray[8] }
${vars.lightSelector} {
background-color: ${vars.colors.gray[0] }
}
${vars.darkSelector} {
background-color: ${vars.colors.gray[8] }
}
}
`
7 changes: 6 additions & 1 deletion app/frontend/Components/Table/SearchInput/ColumnPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { useTableContext } from '../TableContext'
import { Button } from '@mantine/core'
import { usePageProps } from '@/lib/hooks'

import cx from 'clsx'
import * as classes from '../Table.css'

const ColumnPicker = () => {
const { auth: { user } } = usePageProps()
const { tableState: { hideable, columns, model } } = useTableContext()
Expand All @@ -34,7 +37,9 @@ const ColumnPicker = () => {
return (
<Menu closeOnItemClick={ false } position="bottom-end">
<Menu.Target>
<Button size="md" p="xs"><ColumnsIcon size={ 24 } /></Button>
<Button size="md" p="xs" className={ cx(classes.columnPickerButton) }>
<ColumnsIcon size={ 24 } />
</Button>
</Menu.Target>

<Menu.Dropdown>
Expand Down
7 changes: 7 additions & 0 deletions app/frontend/Components/Table/Table.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,16 @@ export const searchInput = css`
input {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-top-left-radius: ${vars.radius.sm};
border-bottom-left-radius: ${vars.radius.sm};
}
`

export const columnPickerButton = css`
border-top-left-radius: 0;
border-bottom-left-radius: 0;
`

export const pagination = css`
display: inline-block;
max-width: 60px;
Expand Down
6 changes: 1 addition & 5 deletions app/frontend/Features/Contactable/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import Phone from './Phone'
import Email from './Email'
import Website from './Website'

interface ContactableFormProps {
contact: Schema.ContactsFormData
}

const ContactableForm = ({ contact }: ContactableFormProps) => {
const ContactableForm = () => {
return (
<FieldsFor model="contact" legend="Contact Details">

Expand Down
6 changes: 5 additions & 1 deletion app/frontend/Pages/Consumables/ReplenishButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Routes } from '@/lib'
import axios from 'axios'
import { router } from '@inertiajs/react'
import { type UseFormProps } from 'use-inertia-form'
import { useContrastingTextColor } from '@/lib/hooks'

const defaultData = { consumable: { qty: 1 } }

Expand Down Expand Up @@ -49,6 +50,8 @@ const ReplenishButton = ({ consumable, disabled, tooltipMessage, ...props }: Rep
return false
}

const textColor = useContrastingTextColor(replenishButtonColor)

return (
<>
<Modal
Expand Down Expand Up @@ -76,10 +79,11 @@ const ReplenishButton = ({ consumable, disabled, tooltipMessage, ...props }: Rep
position="left"
transitionProps={ { transition: 'fade' } }
color={ replenishButtonColor }
c={ textColor }
aria-label={ `Replenish ${consumable.name}` }
>
<Button color={ replenishButtonColor } { ...props } size="sm" onClick={ () => setOpened(true) }>
<ReplenishIcon />
<ReplenishIcon color={ textColor } />
</Button>
</Tooltip>
</>
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/Pages/People/Edit/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useBooleanToggle } from '@/lib/hooks'
import { FormPeopleDropdown, FormDepartmentsDropdown } from '@/Features/Dropdowns'
import { coerceArray } from '@/lib'
import { type HTTPVerb, type UseFormProps } from 'use-inertia-form'
import { ContactForm } from '@/Features'

type PersonFormData = {
person: Schema.PeopleEdit
Expand Down Expand Up @@ -213,6 +214,8 @@ const PersonForm = ({
</FieldsFor>
</FormGroup> }

<ContactForm />

<Grid.Col>
<Submit>
{ person.id ? 'Update' : 'Create' } Person
Expand Down
1 change: 1 addition & 0 deletions app/frontend/lib/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export { default as useCheckboxState } from './useCheckboxState'
export { default as useLocation } from './useLocation'
export { default as usePageProps } from './usePageProps'
export { default as useInit } from './useInit'
export { default as useContrastingTextColor } from './useContrastingTextColor'
export { default as useCurrency, type UseCurrencyOptions } from './useCurrency'
export { useListState, useToggle, useViewportSize } from '@mantine/hooks'
18 changes: 18 additions & 0 deletions app/frontend/lib/hooks/useContrastingTextColor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isLightColor, type MantinePrimaryShade, useMantineColorScheme, useMantineTheme } from '@mantine/core'

const useContrastingTextColor = (color: string) => {
const { colors, primaryShade } = useMantineTheme()
const { colorScheme } = useMantineColorScheme()

if(color === undefined) return 'black'

let validatedColor = color
if(Object.keys(colors).includes(color)) {
const shade = (primaryShade as MantinePrimaryShade)[(colorScheme as 'light'|'dark')]
validatedColor = colors[color][shade]
}

return isLightColor(validatedColor, 0.379) ? 'black' : 'white'
}

export default useContrastingTextColor

0 comments on commit 88bb564

Please sign in to comment.