Skip to content

Commit

Permalink
refactor(react-18): replace remaining defaultProps manually
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Sep 14, 2024
1 parent 9ea2960 commit 2d1474b
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export default {
parameters: { docs: { description: { component: description } } },
args: {
// Handle default props bug (see Transfer stories)
...FileInputFieldWithList.defaultProps,
dataTest: 'dhis2-uiwidgets-fileinputfieldwithlist',
files: [],
buttonLabel: 'Upload a file',
placeholder: 'No file uploaded yet',
removeText: 'Remove',
multiple: true,
onChange: onChange,
name: 'uploadName',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default {
// Default args:
args: {
// Handle default values (see comment in Transfer.js)
...FileInputField.defaultProps,
accept: '*',
dataTest: 'dhis2-uiwidgets-fileinputfield',
placeholder: 'No file uploaded yet',
onChange: onChange,
name: 'uploadName',
label: 'Upload something',
Expand Down
6 changes: 5 additions & 1 deletion components/layer/src/layer.prod.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default {
},
},
// Handle weird treatment of non-literal defaultProps (see Transfer.stories)
args: { ...Layer.defaultProps },
args: {
position: 'fixed',
dataTest: 'dhis2-uicore-layer',
level: 'auto',
},
}

const Template = (args) => (
Expand Down
4 changes: 2 additions & 2 deletions components/pagination/src/__tests__/page-summary.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { shallow } from 'enzyme'
import React from 'react'
import { getDefaultPageSummaryText } from '../get-default-page-summary-text.js'
import { PageSummary } from '../page-summary.js'
import { Pagination } from '../pagination.js'

describe('<PageSummary />', () => {
const props = {
dataTest: 'test',
pageSummaryText: Pagination.defaultProps.pageSummaryText,
pageSummaryText: getDefaultPageSummaryText,
}

it('renders without errors', () => {
Expand Down
8 changes: 7 additions & 1 deletion components/popover/src/popover.prod.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export default {
},
},
// Handles weird treatment of non-literal args (`elevation: elevations.e200`)
args: { ...Popover.defaultProps },
args: {
arrow: true,
dataTest: 'dhis2-uicore-popover',
elevation: elevations.e200,
maxWidth: 360,
placement: 'top',
},
argTypes: {
reference: { ...sharedPropTypes.popperReferenceArgType },
placement: { ...sharedPropTypes.popperPlacementArgType },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ export default {
// default args for stories
args: {
// Fix default prop issues - causes 'i18n is not defined' error
...MultiSelectField.defaultProps,
dataTest: 'dhis2-uiwidgets-multiselectfield',
clearText: 'Clear',
empty: 'No data found',
filterPlaceholder: 'Type to filter options',
loadingText: 'Loading options',
noMatchText: 'No options found',

label: 'Default label',
selected: ['1'],
children: options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ export default {
// default args for stories
args: {
// Fix default prop issues - causes 'i18n is not defined' error
...SingleSelectField.defaultProps,
dataTest: 'dhis2-uiwidgets-singleselectfield',
selected: '',

clearText: 'Clear',
empty: 'No data found',
filterPlaceholder: 'Type to filter options',
loadingText: 'Loading options',
noMatchText: 'No options found',

label: 'Default label',
children: options,
onChange: onChange,
Expand Down
14 changes: 12 additions & 2 deletions components/transfer/src/transfer.prod.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ export default {
},
// Default args:
args: {
...Transfer.defaultProps,
dataTest: 'dhis2-uicore-transfer',
height: '240px',
initialSearchTerm: '',
initialSearchTermPicked: '',
maxSelections: Infinity,
optionsWidth: '320px',
selected: [],
selectedWidth: '320px',
options: options,
},
}
Expand Down Expand Up @@ -242,7 +249,10 @@ const RenderOptionCode = () => (
</>
)

const StatefulTemplateCustomRenderOption = ({ initiallySelected = [], ...args }) => {
const StatefulTemplateCustomRenderOption = ({
initiallySelected = [],
...args
}) => {
const [selected, setSelected] = useState(initiallySelected)
const onChange = (payload) => setSelected(payload.selected)

Expand Down
7 changes: 1 addition & 6 deletions docs/src/components/DemoComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useRef } from 'react'
import { DEMO_URL } from '../constants.js'
import styles from './DemoComponent.module.css'

export const Demo = ({ path, args, height }) => {
export const Demo = ({ path, args = '', height = '100px' }) => {
const iframeRef = useRef(null)

const handleReload = () => {
Expand Down Expand Up @@ -73,8 +73,3 @@ Demo.propTypes = {
args: PropTypes.string,
height: PropTypes.string,
}

Demo.defaultProps = {
args: '',
height: '100px',
}

0 comments on commit 2d1474b

Please sign in to comment.