Skip to content

Commit

Permalink
feat: update react peer dependency to react@18
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Oct 28, 2024
1 parent 3b5c73c commit 00a1027
Show file tree
Hide file tree
Showing 56 changed files with 1,267 additions and 691 deletions.
4 changes: 2 additions & 2 deletions collections/forms/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-09-09T12:09:30.724Z\n"
"PO-Revision-Date: 2024-09-09T12:09:30.724Z\n"
"POT-Creation-Date: 2024-10-28T16:04:48.401Z\n"
"PO-Revision-Date: 2024-10-28T16:04:48.402Z\n"

msgid "Upload file"
msgstr "Upload file"
Expand Down
8 changes: 4 additions & 4 deletions collections/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"build": "d2-app-scripts build"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13"
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18"
},
"dependencies": {
"@dhis2/prop-types": "^3.1.2",
Expand All @@ -54,8 +54,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13"
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"types": "types"
}
66 changes: 66 additions & 0 deletions collections/forms/src/CalendarInputFF/CalendarInputFF.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { CalendarInput } from '@dhis2-ui/calendar'

Check failure on line 1 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'@dhis2-ui/calendar' should be listed in the project's dependencies. Run 'npm i -S @dhis2-ui/calendar' to add it
import PropTypes from 'prop-types'
import React from 'react'
import {
hasError,

Check failure on line 5 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'hasError' is defined but never used
isValid,

Check failure on line 6 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'isValid' is defined but never used
getValidationText,

Check failure on line 7 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'getValidationText' is defined but never used
isLoading,

Check failure on line 8 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'isLoading' is defined but never used
createFocusHandler,
createChangeHandler,
createBlurHandler,
} from '../shared/helpers.js'
import { metaPropType, inputPropType } from '../shared/propTypes.js'

export const CalendarInputFF = ({
input,
meta,
error,

Check failure on line 18 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'error' is defined but never used
showValidStatus,

Check failure on line 19 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'showValidStatus' is defined but never used
valid,

Check failure on line 20 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'valid' is defined but never used
validationText,

Check failure on line 21 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'validationText' is defined but never used
onBlur,
onFocus,
loading,

Check failure on line 24 in collections/forms/src/CalendarInputFF/CalendarInputFF.js

View workflow job for this annotation

GitHub Actions / lint

'loading' is defined but never used
showLoadingStatus,
...rest
}) => {
console.log('INPUT', meta)
return (
<CalendarInput
{...rest}
name={input.name}
type={input.type}
error={meta.error?.isError}
warning={meta.error?.isWarning}
// warning={!!meta.error}
valid={meta.valid}
validationText={meta.error?.message}
onFocus={createFocusHandler(input, onFocus)}
onChange={createChangeHandler(input)}
onBlur={createBlurHandler(input, onBlur)}
date={input.value}
onDateSelect={(date) => {
input.onChange(date ? date?.calendarDateString : '')
rest.onDateSelect?.(date)
}}
/>
)
}

CalendarInputFF.propTypes = {
/** `input` props received from Final Form `Field` */
input: inputPropType.isRequired,
/** `meta` props received from Final Form `Field` */
meta: metaPropType.isRequired,

error: PropTypes.bool,
loading: PropTypes.bool,
showLoadingStatus: PropTypes.bool,
showValidStatus: PropTypes.bool,
valid: PropTypes.bool,
validationText: PropTypes.string,

onBlur: PropTypes.func,
onFocus: PropTypes.func,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react'
import { Field } from 'react-final-form'
import { formDecorator } from '../formDecorator.js'
import { inputArgType, metaArgType } from '../shared/propTypes.js'
import { isValidDate } from '../validators/index.js'
import { CalendarInputFF } from './CalendarInputFF.js'

const description = `
The \`CalendarInputFF\` is a wrapper around a \`CalendarInput\` that enables it to work with Final Form, the preferred library for form validation and utilities in DHIS 2 apps.
#### Final Form
See how to use Final Form at [Final Form - Getting Started](https://final-form.org/docs/react-final-form/getting-started).
Inside a Final Form \`<Form>\` component, these 'FF' UI components are intended to be used in the \`component\` prop of the [Final Form \`<Field>\` components](https://final-form.org/docs/react-final-form/api/Field) where they will receive some props from the Field, e.g. \`<Field component={CalendarInputFF} />\`. See the code samples below for examples.
#### Props
The props shown in the table below are generally provided to the \`CalendarInputFF\` wrapper by the Final Form \`Field\`.
Note that any props beyond the API of the \`Field\` component will be spread to the \`CalendarInputFF\`, which passes any extra props to the underlying \`CalendarInput\` using \`{...rest}\`.
Therefore, to add any props to the \`CalendarInputFF\` or \`CalendarInput\`, add those props to the parent Final Form \`Field\` component.
Also see \`CalendarInput\` for notes about props and implementation.
\`\`\`js
import { CalendarInputFF } from '@dhis2/ui'
\`\`\`
Press **Submit** to see the form values logged to the console.
`

export default {
title: 'Calendar Input Field ',
component: CalendarInputFF,
decorators: [formDecorator],
parameters: { docs: { description: { component: description } } },
argTypes: {
input: { ...inputArgType },
meta: { ...metaArgType },
},
}

export const Default = () => {
const validationOptions = {
maxDateString: '2021-01-01',
strictValidation: false,
}
return (
<Field
name="date"
validate={isValidDate(validationOptions)}
component={CalendarInputFF}
// {...validationOptions}
autoComplete="off"
// strictValidation={false}
// warning
// calendar="ethiopic"
// date="2020-01-01"
/>
)
}
21 changes: 21 additions & 0 deletions collections/forms/src/validators/multiCalendarDateValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { validateDateString } from '@dhis2/multi-calendar-dates'
import i18n from '../locales/index.js'

const isValidDate = (options) => {
return (value) => {
const result = validateDateString(value, options)
console.log('isValid running', value, options, result)
if (result.valid) {
return undefined
} else {
console.log(' > ', result.validationText)
return {
message: result.validationText,
isWarning: !options?.strictValidation,
isError: options?.strictValidation,
}
}
}
}

export { isValidDate }
8 changes: 4 additions & 4 deletions collections/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@
"peerDependencies": {
"@dhis2/app-runtime": "^3",
"@dhis2/d2-i18n": "^1",
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"devDependencies": {
"@dhis2/app-runtime": "^3.9.0",
"@dhis2/d2-i18n": "^1.1.0",
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"files": [
Expand Down
8 changes: 4 additions & 4 deletions components/alert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13",
"react": ">=16.13",
"react-dom": ">=16.13",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -44,8 +44,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
8 changes: 4 additions & 4 deletions components/box/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -42,8 +42,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
8 changes: 4 additions & 4 deletions components/button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -46,8 +46,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
8 changes: 4 additions & 4 deletions components/calendar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
},
"peerDependencies": {
"@dhis2/d2-i18n": "^1",
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -51,8 +51,8 @@
],
"devDependencies": {
"@dhis2/d2-i18n": "^1.1.0",
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
8 changes: 4 additions & 4 deletions components/card/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -42,8 +42,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
8 changes: 4 additions & 4 deletions components/center/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -42,8 +42,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
8 changes: 4 additions & 4 deletions components/checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -44,8 +44,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
8 changes: 4 additions & 4 deletions components/chip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
},
"peerDependencies": {
"react": "^16.13",
"react-dom": "^16.13",
"react": "^16.13 || ^18",
"react-dom": "^16.13 || ^18",
"styled-jsx": "^4"
},
"dependencies": {
Expand All @@ -42,8 +42,8 @@
"types"
],
"devDependencies": {
"react": "16.13",
"react-dom": "16.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-jsx": "^4.0.1"
},
"types": "types"
Expand Down
Loading

0 comments on commit 00a1027

Please sign in to comment.