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

feat(v2/PublicForm): add handling of form color theme, update design #3774

Merged
merged 35 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f34d0cf
feat: add theme-blue to FieldColorScheme enum type
karrui Apr 20, 2022
6c19053
feat: pass colorTheme into YesNoField
karrui Apr 20, 2022
366149c
feat: make Attachment component responsive to colorScheme
karrui Apr 20, 2022
94b75c7
feat: make Menu component responsive to colorScheme
karrui Apr 20, 2022
7d908d3
feat: make DateInput component responsive to colorScheme
karrui Apr 20, 2022
cb98d4f
feat: make SingleSelect component responsive to colorScheme
karrui Apr 20, 2022
f29e51c
feat: make TableField component responsive to colorScheme
karrui Apr 20, 2022
67c83da
feat: make SectionField component responsive to colorTheme
karrui Apr 20, 2022
a01745e
feat: make RatingField component responsive to colorTheme
karrui Apr 20, 2022
d415bc5
feat: make RadioField component responsive to colorTheme
karrui Apr 20, 2022
cd0a561
feat: make NumberField component responsive to colorTheme
karrui Apr 20, 2022
e812bbb
feat: make DropdownField component responsive to colorTheme
karrui Apr 20, 2022
8ce0363
feat: make DateField component responsive to colorTheme
karrui Apr 20, 2022
f0b8892
feat: make CheckboxField component responsive to colorTheme
karrui Apr 20, 2022
e764642
feat: make AttachmentField component responsive to colorTheme
karrui Apr 20, 2022
736b305
feat: make NumberInput component responsive to colorScheme
karrui Apr 20, 2022
cdde247
feat: make Attachment component responsive to colorTheme
karrui Apr 20, 2022
bffc1dd
feat: make public form buttons responsive to colorTheme
karrui Apr 20, 2022
10b3a34
style(Checkbox): add white bg to unchecked checkbox
karrui Apr 20, 2022
b69d1a1
feat(PublicForm): update mobile padding
karrui Apr 20, 2022
c2dbb94
feat: update styling of public form to better fit design
karrui Apr 20, 2022
b7ddee9
feat(PublicFormPage): add stories for color theme variants
karrui Apr 20, 2022
9250193
feat(PublicFormPage): add mobile stories
karrui Apr 20, 2022
726b15b
fix: storybook snapshot regressions
karrui Apr 20, 2022
7dc3e81
style(Button): update backgrounds of theme color scheme
karrui Apr 21, 2022
e6cddb7
feat(FormHeader): update alignment in mobile view
karrui Apr 21, 2022
3f173da
feat: add colorTheme to unauth page login button
karrui Apr 21, 2022
784c393
style(FormAuth): remove login button icon on mobile, update padding
karrui Apr 21, 2022
1bac1fa
feat(AuthImageSvgr): update svg
karrui Apr 21, 2022
edcc595
feat(FormEndPage): add color theme to form end page
karrui Apr 21, 2022
f2ba1fd
style(FormHeader): increase maxW and change to start align on mobile
karrui Apr 22, 2022
ae08fb4
feat: change section field color for orange and red themes
karrui Apr 22, 2022
1444b43
style(Rating): use theme/600 instead of 700 for yellow orange red
karrui Apr 25, 2022
4ed396a
feat(EndPageBlock): remove colortheme styling for accordion
karrui Apr 25, 2022
851049c
style(Button): update colours for outline variant with certain themes
karrui Apr 25, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
import { Props as DayzedProps, RenderProps, useDayzed } from 'dayzed'
import { inRange } from 'lodash'

import { ThemeColorScheme } from '~theme/foundations/colours'

import { DatePickerProps } from '../DatePicker'
import {
generateClassNameForDate,
Expand Down Expand Up @@ -64,6 +66,10 @@ type PassthroughProps = {
* Date currently being hovered, if any.
*/
hoveredDate?: Date
/**
* Color scheme of date input
*/
colorScheme?: ThemeColorScheme
}
export type UseProvideCalendarProps = Pick<DayzedProps, 'monthsToDisplay'> &
PassthroughProps
Expand Down Expand Up @@ -122,6 +128,7 @@ const useProvideCalendar = ({
onMouseLeaveCalendar,
isDateInRange,
hoveredDate,
colorScheme = 'primary',
}: UseProvideCalendarProps) => {
// Ensure that calculations are always made based on date of initial render,
// so component state doesn't suddenly jump at midnight
Expand Down Expand Up @@ -293,5 +300,6 @@ const useProvideCalendar = ({
onMouseLeaveCalendar,
isDateInRange,
hoveredDate,
colorScheme,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { useCalendar } from './CalendarContext'

export const CalendarTodayButton = (): JSX.Element => {
const styles = useStyles()
const { handleTodayClick } = useCalendar()
const { handleTodayClick, colorScheme } = useCalendar()
return (
<Box sx={styles.todayLinkContainer}>
<Button
aria-label="Focus on today's date"
colorScheme={colorScheme}
variant="link"
type="button"
onClick={handleTodayClick}
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/components/DatePicker/Calendar/DayOfMonth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ export interface DayOfMonthProps extends ButtonProps {

export const DayOfMonth = forwardRef<DayOfMonthProps, 'button'>(
(
{
dateObj: { date, selected, today },
isOutsideCurrMonth,
colorScheme = 'primary',
...props
},
{ dateObj: { date, selected, today }, isOutsideCurrMonth, ...props },
ref,
) => {
const {
Expand All @@ -48,6 +43,7 @@ export const DayOfMonth = forwardRef<DayOfMonthProps, 'button'>(
isDateInRange,
selectedDates,
hoveredDate,
colorScheme,
} = useCalendar()

const isAvailable = useMemo(
Expand All @@ -72,6 +68,7 @@ export const DayOfMonth = forwardRef<DayOfMonthProps, 'button'>(
isSelected: selected,
isToday: today,
isOutsideCurrMonth,
colorScheme,
})

const buttonBoxBg = useMemo(() => {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/DatePicker/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import Input, { InputProps } from '../Input'
import { DatePicker, DatePickerProps } from './DatePicker'

export interface DateInputProps
extends Omit<InputProps, 'value' | 'onChange'>,
Pick<DatePickerProps, 'isDateUnavailable'> {
extends Omit<InputProps, 'value' | 'onChange' | 'colorScheme'>,
Pick<DatePickerProps, 'isDateUnavailable' | 'colorScheme'> {
name: string
value?: string
onChange?: (val: string) => void
Expand All @@ -44,6 +44,7 @@ export const DateInput = forwardRef<DateInputProps, 'input'>(
isReadOnly: isReadOnlyProp,
isRequired: isRequiredProp,
isInvalid: isInvalidProp,
colorScheme,
...props
},
ref,
Expand Down Expand Up @@ -118,6 +119,7 @@ export const DateInput = forwardRef<DateInputProps, 'input'>(
</PopoverAnchor>
<PopoverTrigger>
<IconButton
colorScheme={colorScheme}
aria-label={calendarButtonAria}
icon={<BxCalendar />}
variant="inputAttached"
Expand Down Expand Up @@ -152,6 +154,7 @@ export const DateInput = forwardRef<DateInputProps, 'input'>(
</PopoverHeader>
<PopoverBody p={0}>
<DateInput.DatePicker
colorScheme={colorScheme}
date={datePickerDate}
isDateUnavailable={isDateUnavailable}
onSelectDate={handleDatepickerSelection}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@chakra-ui/react'

import { DATE_INPUT_THEME_KEY } from '~theme/components/DateInput'
import { ThemeColorScheme } from '~theme/foundations/colours'

import {
CalendarPanel,
Expand All @@ -27,11 +28,15 @@ export interface DatePickerProps {
* unavailable.
*/
isDateUnavailable?: (d: Date) => boolean
/**
* Color scheme for date picker component
*/
colorScheme?: ThemeColorScheme
}

export const DatePicker = forwardRef<DatePickerProps, 'input'>(
({ date, ...props }, initialFocusRef) => {
const styles = useMultiStyleConfig(DATE_INPUT_THEME_KEY, {})
const styles = useMultiStyleConfig(DATE_INPUT_THEME_KEY, props)

return (
<CalendarProvider {...props} selectedDates={date}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from '@chakra-ui/react'
import { useCombobox, UseComboboxProps } from 'downshift'

import { ThemeColorScheme } from '~theme/foundations/colours'

import { useItems } from '../hooks/useItems'
import { SelectContext, SharedSelectContextReturnProps } from '../SelectContext'
import { ComboboxItem } from '../types'
Expand All @@ -32,6 +34,8 @@ export interface SingleSelectProviderProps<
label: string
}
children: React.ReactNode
/** Color scheme of component */
colorScheme?: ThemeColorScheme
}
export const SingleSelectProvider = ({
items: rawItems,
Expand All @@ -51,6 +55,7 @@ export const SingleSelectProvider = ({
isRequired: isRequiredProp,
children,
inputAria: inputAriaProp,
colorScheme,
comboboxProps = {},
}: SingleSelectProviderProps): JSX.Element => {
const { items, getItemByValue } = useItems({ rawItems })
Expand Down Expand Up @@ -178,6 +183,7 @@ export const SingleSelectProvider = ({

const styles = useMultiStyleConfig('SingleSelect', {
isClearable,
colorScheme,
})

const inputAria = useMemo(() => {
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/components/Field/Attachment/Attachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import omit from 'lodash/omit'
import simplur from 'simplur'

import { ATTACHMENT_THEME_KEY } from '~theme/components/Field/Attachment'
import { ThemeColorScheme } from '~theme/foundations/colours'

import { AttachmentDropzone } from './AttachmentDropzone'
import { AttachmentFileInfo } from './AttachmentFileInfo'
Expand Down Expand Up @@ -56,11 +57,26 @@ export interface AttachmentProps extends UseFormControlProps<HTMLElement> {
* input.
*/
showFileSize?: boolean

/**
* Color scheme of the component.
*/
colorScheme?: ThemeColorScheme
}

export const Attachment = forwardRef<AttachmentProps, 'div'>(
(
{ onChange, onError, maxSize, showFileSize, accept, value, name, ...props },
{
onChange,
onError,
maxSize,
showFileSize,
accept,
value,
name,
colorScheme,
...props
},
ref,
) => {
// Merge given props with any form control props, if they exist.
Expand Down Expand Up @@ -179,6 +195,7 @@ export const Attachment = forwardRef<AttachmentProps, 'div'>(

const styles = useMultiStyleConfig(ATTACHMENT_THEME_KEY, {
isDragActive,
colorScheme,
})

const handleRemoveFile = useCallback(() => {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
useNumberInput,
} from '@chakra-ui/react'

import { ThemeColorScheme } from '~theme/foundations/colours'

import IconButton from '../IconButton'

export interface NumberInputProps extends ChakraNumberInputProps {
Expand All @@ -27,6 +29,11 @@ export interface NumberInputProps extends ChakraNumberInputProps {
* Whether to show the increment and decrement steppers. Defaults to true.
*/
showSteppers?: boolean

/**
* Color scheme of number input.
*/
colorScheme?: ThemeColorScheme
}

export const NumberInput = forwardRef<NumberInputProps, 'input'>(
Expand Down Expand Up @@ -93,6 +100,7 @@ export const NumberInput = forwardRef<NumberInputProps, 'input'>(
<Box __css={styles.stepperWrapper} ref={stepperWrapperRef}>
<IconButton
sx={styles.stepperButton}
colorScheme={props.colorScheme}
aria-hidden
aria-label="Decrement number"
variant="clear"
Expand All @@ -102,6 +110,7 @@ export const NumberInput = forwardRef<NumberInputProps, 'input'>(
<Divider __css={styles.stepperDivider} orientation="vertical" />
<IconButton
sx={styles.stepperButton}
colorScheme={props.colorScheme}
aria-hidden
aria-label="Increment number"
variant="clear"
Expand Down
59 changes: 57 additions & 2 deletions frontend/src/features/public-form/PublicFormPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, Story } from '@storybook/react'

import { BasicField } from '~shared/types/field'
import { FormAuthType } from '~shared/types/form'
import { FormAuthType, FormColorTheme } from '~shared/types/form'

import { envHandlers } from '~/mocks/msw/handlers/env'
import {
Expand All @@ -12,7 +12,7 @@ import {
SHOW_FIELDS_ON_YES_LOGIC,
} from '~/mocks/msw/handlers/public-form'

import { StoryRouter } from '~utils/storybook'
import { getMobileViewParameters, StoryRouter } from '~utils/storybook'

import PublicFormPage from './PublicFormPage'

Expand All @@ -24,6 +24,24 @@ const DEFAULT_MSW_HANDLERS = [
postVerifyVfnOtpResponse(),
]

const generateMswHandlersForColorTheme = (colorTheme: FormColorTheme) => {
return [
...envHandlers,
getPublicFormResponse({
overrides: {
form: {
startPage: {
colorTheme,
},
},
},
}),
postVfnTransactionResponse(),
postGenerateVfnOtpResponse(),
postVerifyVfnOtpResponse(),
]
}

export default {
title: 'Pages/PublicFormPage',
component: PublicFormPage,
Expand All @@ -44,6 +62,34 @@ export default {
const Template: Story = () => <PublicFormPage />
export const Default = Template.bind({})

export const Mobile = Template.bind({})
Mobile.parameters = getMobileViewParameters()

export const ColorThemeGreen = Template.bind({})
ColorThemeGreen.parameters = {
msw: generateMswHandlersForColorTheme(FormColorTheme.Green),
}

export const ColorThemeGrey = Template.bind({})
ColorThemeGrey.parameters = {
msw: generateMswHandlersForColorTheme(FormColorTheme.Grey),
}

export const ColorThemeBrown = Template.bind({})
ColorThemeBrown.parameters = {
msw: generateMswHandlersForColorTheme(FormColorTheme.Brown),
}

export const ColorThemeRed = Template.bind({})
ColorThemeRed.parameters = {
msw: generateMswHandlersForColorTheme(FormColorTheme.Red),
}

export const ColorThemeOrange = Template.bind({})
ColorThemeOrange.parameters = {
msw: generateMswHandlersForColorTheme(FormColorTheme.Orange),
}

export const Loading = Template.bind({})
Loading.parameters = {
msw: [...envHandlers, getPublicFormResponse({ delay: 'infinite' })],
Expand All @@ -60,12 +106,21 @@ SingpassUnauthorized.parameters = {
form: {
title: 'Singpass login form',
authType: FormAuthType.SP,
startPage: {
colorTheme: FormColorTheme.Grey,
},
},
},
}),
],
}

export const UnauthedMobile = Template.bind({})
UnauthedMobile.parameters = {
...SingpassUnauthorized.parameters,
...getMobileViewParameters(),
}

export const SingpassAuthorized = Template.bind({})
SingpassAuthorized.storyName = 'Singpass/Authorized'
SingpassAuthorized.parameters = {
Expand Down
Loading