Skip to content

Commit

Permalink
Simplify prop exclusion for styled components
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier authored and bjoernricks committed Nov 14, 2023
1 parent df31fc7 commit 177128e
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 129 deletions.
11 changes: 6 additions & 5 deletions src/web/components/badge/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ import {isDefined, hasValue} from 'gmp/utils/identity';

import PropTypes from 'web/utils/proptypes';
import Theme from 'web/utils/theme';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

const BadgeContainer = styled.div.withConfig(excludePropsConfig('margin'))`
const BadgeContainer = styledExcludeProps(styled.div, ['margin'])`
position: relative;
display: inline-flex;
margin-right: ${props => props.margin}px;
`;

BadgeContainer.displayName = 'BadgeContainer';

const BadgeIcon = styled.span.withConfig(
excludePropsConfig(['backgroundColor', 'margin']),
)`
const BadgeIcon = styledExcludeProps(styled.span, [
'backgroundColor',
'margin',
])`
display: flex;
flex-direction: row;
flex-wrap: wrap;
Expand Down
8 changes: 3 additions & 5 deletions src/web/components/bar/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import React from 'react';
import styled from 'styled-components';

import PropTypes from 'web/utils/proptypes.js';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';
import Theme from 'web/utils/theme.js';

const ProgressBarBox = styled.div.withConfig(
excludePropsConfig(['boxBackground']),
)`
const ProgressBarBox = styledExcludeProps(styled.div, ['boxBackground'])`
height: 13px;
box-sizing: content-box; /* height includes border */
display: inline-block;
Expand Down Expand Up @@ -66,7 +64,7 @@ export const adjustProgress = progress => {
return progress;
};

const Progress = styled.div.withConfig(excludePropsConfig(['progress']))`
const Progress = styledExcludeProps(styled.div, ['progress'])`
height: 13px;
@media print {
Expand Down
6 changes: 2 additions & 4 deletions src/web/components/dialog/scrollablecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import React from 'react';
import styled from 'styled-components';

import PropTypes from 'web/utils/proptypes';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

import Layout from 'web/components/layout/layout';

const ScrollableContent = styled.div.withConfig(
excludePropsConfig(['maxHeight']),
)`
const ScrollableContent = styledExcludeProps(styled.div, ['maxHeight'])`
overflow: auto;
padding: 0 15px;
width: 100%;
Expand Down
4 changes: 2 additions & 2 deletions src/web/components/folding/folding.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React from 'react';
import styled, {keyframes, css} from 'styled-components';

import PropTypes from 'web/utils/proptypes';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

/**
* State used in foldable components
Expand All @@ -43,7 +43,7 @@ const foldDelay = keyframes`
}
`;

const Div = styled.div.withConfig(excludePropsConfig(['foldState']))`
const Div = styledExcludeProps(styled.div, ['foldState'])`
overflow: hidden;
transition: 0.4s;
Expand Down
6 changes: 2 additions & 4 deletions src/web/components/form/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import PropTypes from 'web/utils/proptypes';

import styled from 'styled-components';

import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';
import Theme from 'web/utils/theme';

import withLayout from 'web/components/layout/withLayout';

export const DISABLED_OPACITY = 0.65;

const StyledInput = styled.input.withConfig(
excludePropsConfig(['convert', 'hasError']),
)`
const StyledInput = styledExcludeProps(styled.input, ['convert', 'hasError'])`
/* use font and line settings from parents not from browser default */
font-family: inherit;
font-size: inherit;
Expand Down
10 changes: 3 additions & 7 deletions src/web/components/form/formgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {parseInt} from 'gmp/parser';

import Layout from 'web/components/layout/layout';
import PropTypes from 'web/utils/proptypes';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

const COLUMNS = [
'0',
Expand All @@ -50,9 +50,7 @@ const FormGroupLayout = styled.div`
padding-bottom: 10px;
`;

const Title = styled.label.withConfig(
excludePropsConfig(['titleSize', 'titleOffset']),
)`
const Title = styledExcludeProps(styled.label, ['titleSize', 'titleOffset'])`
display: inline-block;
max-width: 100%;
font-weight: bold;
Expand All @@ -63,9 +61,7 @@ const Title = styled.label.withConfig(
margin-left: ${props => COLUMNS[props.titleOffset]};
`;

const FormGroupContent = styled(Layout).withConfig(
excludePropsConfig(['size', 'offset']),
)`
const FormGroupContent = styledExcludeProps(styled(Layout), ['size', 'offset'])`
${props => {
const ret = {};
if (isDefined(props.size)) {
Expand Down
6 changes: 2 additions & 4 deletions src/web/components/form/loadingbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import styled from 'styled-components';
import Button from 'web/components/form/button';

import Theme from 'web/utils/theme';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

const LoadingButton = styled(Button).withConfig(
excludePropsConfig('isLoading'),
)`
const LoadingButton = styledExcludeProps(styled(Button), ['isLoading'])`
color: ${props => (props.isLoading ? 'rgba(0, 0, 0, 0.0)' : Theme.darkGray)};
background: ${props =>
props.isLoading
Expand Down
6 changes: 2 additions & 4 deletions src/web/components/form/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {isDefined} from 'gmp/utils/identity';

import compose from 'web/utils/compose';
import PropTypes from 'web/utils/proptypes';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

import Divider from 'web/components/layout/divider';
import withLayout from 'web/components/layout/withLayout';
Expand All @@ -37,9 +37,7 @@ export const StyledElement = styled.label`
${props => (props.disabled ? {cursor: 'not-allowed'} : undefined)};
`;

export const StyledInput = styled.input.withConfig(
excludePropsConfig(['convert']),
)`
export const StyledInput = styledExcludeProps(styled.input, ['convert'])`
/* use font and line settings from parents not from browser default */
font-family: inherit;
font-size: inherit;
Expand Down
4 changes: 2 additions & 2 deletions src/web/components/form/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ import {
} from './selectelements';

import {Marker} from './useFormValidation';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

const SingleSelectedValue = styled(SelectedValue)`
cursor: default;
`;

const Div = styled.div.withConfig(excludePropsConfig(['hasError']))`
const Div = styledExcludeProps(styled.div, ['hasError'])`
display: flex;
`;

Expand Down
12 changes: 4 additions & 8 deletions src/web/components/form/selectelements.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ import {isDefined, hasValue} from 'gmp/utils/identity';

import Theme from 'web/utils/theme';
import PropTypes from 'web/utils/proptypes';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

import Portal from 'web/components/portal/portal';

export const Box = styled.div.withConfig(
excludePropsConfig(['hasError', 'isOpen']),
)`
export const Box = styledExcludeProps(styled.div, ['hasError', 'isOpen'])`
border: 1px solid ${Theme.inputBorderGray};
border-radius: 2px;
display: flex;
Expand Down Expand Up @@ -62,9 +60,7 @@ export const Input = styled.input`
line-height: inherit;
`;

export const Item = styled.span.withConfig(
excludePropsConfig(['isActive', 'isSelected']),
)`
export const Item = styledExcludeProps(styled.span, ['isActive', 'isSelected'])`
padding: 1px 5px;
cursor: pointer;
&:hover {
Expand All @@ -89,7 +85,7 @@ export const ItemContainer = styled.div`
flex-direction: column;
`;

const MenuContainer = styled.div.withConfig(excludePropsConfig(['position']))`
const MenuContainer = styledExcludeProps(styled.div, ['position'])`
outline: 0;
border-radius: 0 0 4px 4px;
transition: opacity 0.1s ease;
Expand Down
9 changes: 5 additions & 4 deletions src/web/components/form/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import withLayout from 'web/components/layout/withLayout';

import {DISABLED_OPACITY} from './field';
import {Marker} from './useFormValidation';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

const StyledTextArea = styled.textarea.withConfig(
excludePropsConfig(['convert', 'hasError']),
)`
const StyledTextArea = styledExcludeProps(styled.textarea, [
'convert',
'hasError',
])`
display: block;
height: auto;
color: ${Theme.darkGray};
Expand Down
4 changes: 2 additions & 2 deletions src/web/components/form/useFormValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import {_, _l} from 'gmp/locale/lang';

import {hasValue, isDefined, isFunction} from 'gmp/utils/identity';

import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';
import Theme from 'web/utils/theme';

const StyledMarker = styled.div.withConfig(excludePropsConfig(['isVisible']))`
const StyledMarker = styledExcludeProps(styled.div, ['isVisible'])`
color: ${Theme.darkRed};
color: ${props => props.color};
font-weight: bold;
Expand Down
6 changes: 2 additions & 4 deletions src/web/components/icon/svgicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ import PropTypes from 'web/utils/proptypes';
import Theme from 'web/utils/theme';

import withIconSize from 'web/components/icon/withIconSize';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

const Anchor = styled.a`
display: flex;
`;

const Styled = styled.span.withConfig(
excludePropsConfig(['active', 'isLoading']),
)`
const Styled = styledExcludeProps(styled.span, ['active', 'isLoading'])`
cursor: ${props => (isDefined(props.onClick) ? 'pointer' : undefined)};
@media print {
Expand Down
6 changes: 2 additions & 4 deletions src/web/components/icon/withIconSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {isArray} from 'gmp/utils/identity';
import {IconSizeContext} from 'web/components/provider/iconsizeprovider';

import PropTypes from 'web/utils/proptypes';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

export const ICON_SIZE_LARGE_PIXELS = '50px';
export const ICON_SIZE_MEDIUM_PIXELS = '24px';
Expand All @@ -35,9 +35,7 @@ export const ICON_SIZE_SMALL_PIXELS = '16px';
const withIconSize =
(defaultSize = 'small') =>
Component => {
const IconSize = styled(Component).withConfig(
excludePropsConfig(['iconSize']),
)`
const IconSize = styledExcludeProps(styled(Component), ['iconSize'])`
${props => {
const {iconSize = defaultSize, size = iconSize} = props;
Expand Down
9 changes: 5 additions & 4 deletions src/web/components/label/severityclass.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import React from 'react';
import styled from 'styled-components';

import _ from 'gmp/locale';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

const Label = styled.div.withConfig(
excludePropsConfig(['backgroundColor', 'borderColor']),
)`
const Label = styledExcludeProps(styled.div, [
'backgroundColor',
'borderColor',
])`
text-align: center;
font-weight: normal;
font-style: normal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,17 @@ exports[`HorizontalSep tests should allow to wrap 1`] = `
}
.c2 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: start;
-ms-flex-pack: start;
-webkit-justify-content: start;
justify-content: start;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.c3 {
margin-left: -5px;
}
.c3>* {
.c2>* {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
}
.c3>* {
.c2>* {
margin-left: 5px;
}
Expand All @@ -63,14 +41,14 @@ exports[`HorizontalSep tests should allow to wrap 1`] = `
display: inline-flex;
}
.c4 {
.c3 {
-webkit-box-flex-wrap: true;
-webkit-flex-wrap: true;
-ms-flex-wrap: true;
flex-wrap: true;
}
.c4>*:not(:last-child)::after {
.c3>*:not(:last-child)::after {
content: '';
margin-left: 5px;
}
Expand All @@ -79,7 +57,7 @@ exports[`HorizontalSep tests should allow to wrap 1`] = `
class="c0 c1"
>
<div
class="c2 c3 c4"
class="c0 c2 c3"
/>
</div>
`;
Expand Down Expand Up @@ -245,7 +223,6 @@ exports[`HorizontalSep tests should render with spacing 1`] = `
>
<div
class="c0 c2 c3"
spacing="10px"
/>
</div>
`;
6 changes: 2 additions & 4 deletions src/web/components/layout/divider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import React from 'react';
import styled from 'styled-components';

import PropTypes from 'web/utils/proptypes';
import {excludePropsConfig} from 'web/utils/styledConfig';
import {styledExcludeProps} from 'web/utils/styledConfig';

import Layout from './layout';

const DEFAULT_MARGIN = '5px';

const DividerComponent = styled(Layout).withConfig(
excludePropsConfig('margin'),
)`
const DividerComponent = styledExcludeProps(styled(Layout), ['margin'])`
& > * {
display: inline-flex;
}
Expand Down
Loading

0 comments on commit 177128e

Please sign in to comment.