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

Replace the HOCs #3811

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"plugins": [
"@babel/plugin-transform-flow-strip-types"
"@babel/plugin-transform-flow-strip-types",
["styled-jsx/babel"]
]
}
10 changes: 9 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@
]
}
],
"import/extensions": ["error", "never"]
"import/extensions": ["error", "never"],
"react/no-unknown-property": [
2,
{
"ignore": [
"jsx"
]
}
]
},
"settings": {
"import/resolver": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
// @flow
import * as React from 'react';
import { withStyles } from '@material-ui/core/styles';
import { theme } from '../../../../styles/theme';

type Props = {
classes: {
borderBox: string,
},
contentClassName?: ?string,
children: React.Node,
};

const styles = (theme: Theme) => ({
borderBox: {
borderRadius: theme.typography.pxToRem(6),
borderWidth: theme.typography.pxToRem(2),
borderColor: '#e0e0e0',
borderStyle: 'solid',
},
});

const BorderBoxPlain = (props: Props) => {
const { classes, children, contentClassName } = props;
export const BorderBox = (props: Props) => {
const { children, contentClassName } = props;
return (
<div className={classes.borderBox}>
<div className="borderBox">
<div className={contentClassName}>
{children}
</div>
<style jsx>{`
.borderBox {
border-radius: ${theme.typography.pxToRem(6)};
border-width: ${theme.typography.pxToRem(2)};
border-color: #e0e0e0;
border-style: solid;
}
`}</style>
</div>
);
};

export const BorderBox = withStyles(styles)(BorderBoxPlain);
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// @flow
import type { ComponentType } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import i18n from '@dhis2/d2-i18n';
import { withStyles } from '@material-ui/core/styles';
import { colors, IconChevronRight16 } from '@dhis2/ui';
import { useWorkingListLabel } from './hooks/useWorkingListLabel';
import { BreadcrumbItem } from '../common/BreadcrumbItem';
Expand All @@ -20,6 +18,8 @@ type Props = {
programId: string,
userInteractionInProgress?: boolean,
trackedEntityName?: string,
eventStatus?: string,
page?: string,
};

export const EventStatuses = {
Expand All @@ -30,13 +30,6 @@ export const EventStatuses = {
OVERDUE: 'OVERDUE',
};

const styles = {
container: {
display: 'flex',
alignItems: 'center',
},
};

const pageKeys = Object.freeze({
MAIN_PAGE: 'mainPage',
...EnrollmentPageKeys,
Expand All @@ -45,7 +38,7 @@ const pageKeys = Object.freeze({
const eventIsScheduled = eventStatus => [EventStatuses.SCHEDULE, EventStatuses.OVERDUE, EventStatuses.SKIPPED]
.includes(eventStatus);

const BreadcrumbsPlain = ({
export const EnrollmentBreadcrumb = ({
onBackToMainPage,
onBackToDashboard,
onBackToViewEvent,
Expand All @@ -55,8 +48,7 @@ const BreadcrumbsPlain = ({
displayFrontPageList,
userInteractionInProgress = false,
page,
classes,
}) => {
}: Props) => {
const [openWarning, setOpenWarning] = useState(null);

const { label } = useWorkingListLabel({
Expand Down Expand Up @@ -121,7 +113,7 @@ const BreadcrumbsPlain = ({
]);

return (
<div className={classes.container}>
<div className="container">
{breadcrumbItems.map((button, index) => (
<React.Fragment key={button.key}>
<BreadcrumbItem
Expand Down Expand Up @@ -165,8 +157,14 @@ const BreadcrumbsPlain = ({
onCancel={() => setOpenWarning(null)}
{...defaultDialogProps}
/>

<style jsx>{`
.container {
display: flex;
align-items: center;
}
`}</style>
</div>
);
};

export const EnrollmentBreadcrumb: ComponentType<$Diff<Props, CssClasses>> = withStyles(styles)(BreadcrumbsPlain);
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow
import React, { type ComponentType } from 'react';
import React from 'react';
import cx from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import { colors } from '@dhis2/ui';

type Props = {
Expand All @@ -11,39 +10,38 @@ type Props = {
dataTest: string,
};

const styles = {
button: {
// Reset button styles
background: 'none',
border: 'none',
cursor: 'pointer',
font: 'inherit',

// Custom button styles
fontSize: '14px',
padding: '6px 4px',
color: colors.grey800,
borderRadius: '3px',

'&:hover': {
textDecoration: 'underline',
color: 'black',
},
'&.selected': {
color: 'black',
},
},
};

const BreadcrumbItemPlain = ({ label, onClick, selected, dataTest, classes }) => (
export const BreadcrumbItem = ({ label, onClick, selected, dataTest }: Props) => (
<button
type="button"
className={cx(classes.button, { selected })}
className={cx('button', { selected })}
onClick={onClick}
data-test={dataTest}
>
{label}
<style jsx>{`
.button {
/* Reset button styles */
background: none;
border: none;
cursor: pointer;
font: inherit;

/* Custom button styles */
font-size: 14px;
padding: 6px 4px;
color: ${colors.grey800};
border-radius: 3px;
}

.button:hover {
text-decoration: underline;
color: black;
}

.button.selected {
color: black;
}
`}</style>
</button>
);

export const BreadcrumbItem: ComponentType<$Diff<Props, CssClasses>> = withStyles(styles)(BreadcrumbItemPlain);
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import React from 'react';
import { withStyles } from '@material-ui/core';
import i18n from '@dhis2/d2-i18n';
import { Button } from '@dhis2/ui';
import { useDispatch } from 'react-redux';
Expand All @@ -9,6 +8,7 @@ import { availableCardListButtonState, enrollmentTypes } from './CardList.consta
import {
navigateToEnrollmentOverview,
} from '../../actions/navigateToEnrollmentOverview/navigateToEnrollmentOverview.actions';
import { theme } from '../../../../styles/theme';

type Props = {
currentSearchScopeId?: string,
Expand All @@ -19,14 +19,6 @@ type Props = {
programName?: string,
}

const buttonStyles = (theme: Theme) => ({
buttonMargin: {
'&:not(:first-child)': {
marginLeft: theme.typography.pxToRem(8),
},
},
});

const deriveNavigationButtonState = (type): $Keys<typeof availableCardListButtonState> => {
switch (type) {
case enrollmentTypes.ACTIVE:
Expand All @@ -39,20 +31,44 @@ const deriveNavigationButtonState = (type): $Keys<typeof availableCardListButton
}
};

const ActionButtons = withStyles(buttonStyles)(({ buttonProps, classes }) => (
<>{buttonProps.map(props => (
!props.hide && <Button
small
className={classes.buttonMargin}
dataTest={props.dataTest}
onClick={props.onClick}
>
{props.label}
</Button>
))}</>
));

const CardListButtons = ({
const ActionButton = ({ dataTest, onClick, label, hide }) => {
if (hide) return null;

return (
<>
<Button
small
className="buttonMargin"
dataTest={dataTest}
onClick={onClick}
>
{label}
</Button>
<style jsx>{`
:global(.button-margin:not(:first-child)) {
margin-left: ${theme.typography.pxToRem(8)};
}
`}</style>
</>
);
};

const ActionButtons = ({ buttonProps }: { buttonProps: Array<Object>}) => (
<>
{buttonProps.map((props, index) => (
<ActionButton
key={props.dataTest || index}
dataTest={props.dataTest}
onClick={props.onClick}
label={props.label}
hide={props.hide}
/>
))}
</>
);

export const CardListButtons = ({
currentSearchScopeId,
currentSearchScopeType,
id,
Expand Down Expand Up @@ -108,4 +124,3 @@ const CardListButtons = ({
return <ActionButtons buttonProps={buttonLists} />;
};

export { CardListButtons };
Loading
Loading