Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/WSDEV-5068-section-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhoomi-Pipalia committed Jan 15, 2025
2 parents d3a9604 + 121b52d commit 973e297
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 26 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ Prefix the change with one of these keywords:
- `Nav`: navigation and priority plus work properly with any LinkProvider
- `StackedList`: Removed gap in dividing lines in listings

## [0.18.15]

### Added

- React reference to Form components

### Fixed

- Navigation and Priority Plus work properly with any LinkProvider

## [0.18.14]

### Changed
Expand Down
6 changes: 4 additions & 2 deletions lib/components/Form/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { forwardRef } from 'react'
import { Field } from 'formik'
import { FieldSetComponentProps } from '../FormFieldSet/FormFieldSet'
import { fieldStyles } from '../form.Styles'
Expand All @@ -13,7 +14,7 @@ export interface CheckboxProps extends FieldSetComponentProps {
refs?: Ref<HTMLInputElement | HTMLSelectElement>
}

export const Checkbox = ({ ...props }: CheckboxProps) => {
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(({ ...props }, ref) => {
const { name, options, checkBoxRight, ...rest } = props
const errorClass = useErrorClass(name)

Expand All @@ -27,11 +28,12 @@ export const Checkbox = ({ ...props }: CheckboxProps) => {
name={name}
value={option.value}
className={`${fieldStyles.disabled} ${errorClass}`}
innerRef={ref}
{...rest}
/>
{option.label}
</label>
))}
</>
)
}
})
10 changes: 6 additions & 4 deletions lib/components/Form/FieldControl/FieldControl.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { forwardRef } from 'react'
import { Input } from '../Input/Input'
import { TextArea } from '../TextArea/TextArea'
import { Select } from '../Select/Select'
Expand All @@ -21,7 +22,7 @@ export interface FieldControlSetProps extends FieldSetProps {
[key: string]: any
}

export const FieldControl = ({ ...props }: FieldControlProps | FieldControlSetProps) => {
export const FieldControl = forwardRef<HTMLInputElement, FieldControlProps>(({ ...props }, ref) => {
const {
control,
name,
Expand Down Expand Up @@ -71,7 +72,7 @@ export const FieldControl = ({ ...props }: FieldControlProps | FieldControlSetPr
displayError={displayError}
hiddenLabel={hiddenLabel}
>
{Component && <Component name={name} {...rest} />}
{Component && <Component name={name} innerRef={ref} {...rest} />}
</FormField>
)
}
Expand All @@ -93,12 +94,13 @@ export const FieldControl = ({ ...props }: FieldControlProps | FieldControlSetPr
hiddenLabel={hiddenLabel}
{...rest}
>
<Component name={name} {...rest} />
<Component name={name} innerRef={ref} {...rest} />
</FormFieldSet>
)
}

default:
return null
}
}
})
export default FieldControl
7 changes: 4 additions & 3 deletions lib/components/Form/FileUpload/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useState, forwardRef } from 'react'
import { fieldStyles } from '../form.Styles'
import { FieldComponentProps } from '../FormField/FormField'
import useErrorClass from '../UseError'
Expand All @@ -12,7 +12,7 @@ export interface FileUploadProps extends FieldComponentProps {
handleOnDelete?: () => void
}

export const FileUpload = ({ ...props }: FileUploadProps) => {
export const FileUpload = forwardRef<HTMLInputElement, FileUploadProps>(({ ...props }, ref) => {
const { name, onChange, displayPreview = true, setFieldValue = true, preview, handleOnDelete, ...rest } = props
const errorClass = useErrorClass(name)

Expand Down Expand Up @@ -82,6 +82,7 @@ export const FileUpload = ({ ...props }: FileUploadProps) => {
name={name}
className={fieldStyles.uploads + ' ' + fieldStyles.disabled + errorClass}
onChange={handleMediaChange}
ref={ref}
{...rest}
/>
{displayPreview && previews && previews.length > 0 && (
Expand Down Expand Up @@ -109,4 +110,4 @@ export const FileUpload = ({ ...props }: FileUploadProps) => {
)}
</div>
)
}
})
28 changes: 26 additions & 2 deletions lib/components/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { MouseEventHandler, useMemo, useState } from 'react'
import React, { MouseEventHandler, useMemo, useState, useRef, useEffect } from 'react'
import { type Meta, type StoryObj } from '@storybook/react'
import { useFormik } from 'formik'
import { FormikHelpers } from 'formik'
Expand Down Expand Up @@ -26,6 +26,10 @@ export default meta

type Story = StoryObj<typeof Form>

const sleep = (seconds: number) => {
return new Promise((resolve) => setTimeout(resolve, seconds))
}

export const Input: Story = () => {
type IInput = {
inputText: string
Expand Down Expand Up @@ -56,6 +60,24 @@ export const Input: Story = () => {
onSubmit,
})

const [inputDisabled, setInputDisabled] = useState(false)

const input = useRef<HTMLInputElement>(null)

const handleChange = async (e) => {
console.log(e.currentTarget.value)
formikProps.setFieldValue('inputText', e.currentTarget.value)
setInputDisabled(true)
await sleep(1000)
setInputDisabled(false)
}

useEffect(() => {
if (!inputDisabled) {
input?.current?.focus()
}
}, [inputDisabled])

return (
<Form formikProps={formikProps}>
<Form.FieldGroup>
Expand All @@ -66,7 +88,9 @@ export const Input: Story = () => {
required
helper="Helper Text"
helperpostop
disabled={formikProps.isSubmitting}
disabled={formikProps.isSubmitting || inputDisabled}
ref={input}
onChange={handleChange}
/>
</Form.FieldGroup>
<ButtonGroup>
Expand Down
1 change: 1 addition & 0 deletions lib/components/Form/FormField/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type maxWidthKeys = keyof typeof maxWidthClasses
export interface FieldComponentProps {
name: string
required?: boolean
innerRef?: React.Ref<HTMLInputElement>
}

export interface FieldProps extends FieldComponentProps {
Expand Down
1 change: 1 addition & 0 deletions lib/components/Form/FormFieldSet/FormFieldSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type maxWidthKeys = keyof typeof maxWidthClasses
export interface FieldSetComponentProps {
name: string
required?: boolean
innerRef?: React.Ref<HTMLInputElement>
}

export interface FieldSetProps extends FieldSetComponentProps {
Expand Down
6 changes: 4 additions & 2 deletions lib/components/Form/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React, { forwardRef } from 'react'
import { Field } from 'formik'
import { fieldStyles } from '../form.Styles'
import { FieldComponentProps } from '../FormField/FormField'
Expand All @@ -9,7 +10,7 @@ export interface InputProps extends FieldComponentProps {
disabled?: boolean
}

export const Input = ({ ...props }: InputProps) => {
export const Input = forwardRef<HTMLInputElement, InputProps>(({ ...props }, ref) => {
const { name, hasPrefix, hasSuffix, disabled, ...rest } = props

const errorClass = useErrorClass(name)
Expand All @@ -23,9 +24,10 @@ export const Input = ({ ...props }: InputProps) => {
name={name}
disabled={disabled}
className={`border-none w-full ${errorClass} ${disabled ? fieldStyles.disabled : ''} `}
innerRef={ref}
{...rest}
/>
{hasSuffix && hasSuffix}
</div>
)
}
})
6 changes: 4 additions & 2 deletions lib/components/Form/Radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { forwardRef } from 'react'
import { Field } from 'formik'
import { FieldSetComponentProps } from '../FormFieldSet/FormFieldSet'
import { fieldStyles } from '../form.Styles'
Expand All @@ -12,7 +13,7 @@ export interface RadioProps extends FieldSetComponentProps {
refs?: Ref<HTMLInputElement | HTMLSelectElement>
}

export const Radio = ({ ...props }: RadioProps) => {
export const Radio = forwardRef<HTMLInputElement, RadioProps>(({ ...props }, ref) => {
const { name, options, ...rest } = props

const errorClass = useErrorClass(name)
Expand All @@ -27,11 +28,12 @@ export const Radio = ({ ...props }: RadioProps) => {
name={name}
className={`${fieldStyles.disabled} ${errorClass}`}
value={option.value}
innerRef={ref}
{...rest}
/>
{option.label}
</label>
))}
</>
)
}
})
18 changes: 10 additions & 8 deletions lib/components/Form/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'use client'
import { forwardRef } from 'react'
import { Field } from 'formik'
import { fieldStyles } from '../form.Styles'
import { FieldComponentProps } from '../FormField/FormField'
import useErrorClass from '../UseError'
import { Ref } from 'react'

export interface SelectOptions {
label: string
value: string
}
export interface SelectProps extends FieldComponentProps {
options?: {
label: string
value: string
}[]
options?: SelectOptions[]
refs?: Ref<HTMLInputElement | HTMLSelectElement>
}

export const Select = ({ ...props }: SelectProps) => {
export const Select = forwardRef<HTMLInputElement, SelectProps>(({ ...props }, ref) => {
const { name, options, ...rest } = props

const errorClass = useErrorClass(name)
Expand All @@ -24,10 +25,11 @@ export const Select = ({ ...props }: SelectProps) => {
id={name}
name={name}
className={`${fieldStyles.input} ${fieldStyles.disabled} ${errorClass}`}
innerRef={ref}
{...rest}
>
{options &&
options.map((option) => {
options.map((option: SelectOptions) => {
return (
<option key={option.value} value={option.value}>
{option.label}
Expand All @@ -36,4 +38,4 @@ export const Select = ({ ...props }: SelectProps) => {
})}
</Field>
)
}
})
6 changes: 4 additions & 2 deletions lib/components/Form/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { forwardRef } from 'react'
import { Field } from 'formik'
import { fieldStyles } from '../form.Styles'
import { FieldComponentProps } from '../FormField/FormField'
import useErrorClass from '../UseError'

export const TextArea = ({ ...props }: FieldComponentProps) => {
export const TextArea = forwardRef<HTMLInputElement, FieldComponentProps>(({ ...props }, ref) => {
const { name, ...rest } = props

const errorClass = useErrorClass(name)
Expand All @@ -14,7 +15,8 @@ export const TextArea = ({ ...props }: FieldComponentProps) => {
id={name}
name={name}
className={`${fieldStyles.input} ${fieldStyles.disabled} ${errorClass}`}
innerRef={ref}
{...rest}
/>
)
}
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carletonuniversity/rds",
"version": "0.18.14",
"version": "0.18.15",
"private": false,
"description": "Raven Design System is Carleton University's design system",
"author": "Web Services",
Expand Down

0 comments on commit 973e297

Please sign in to comment.