Skip to content

Commit

Permalink
feat: refactor panel components to use CSS modules and improve class …
Browse files Browse the repository at this point in the history
…naming
  • Loading branch information
andres-mestra committed Nov 3, 2024
1 parent 50900c1 commit 242de0c
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 145 deletions.
17 changes: 9 additions & 8 deletions src/designer/panels/Column.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import React, {Component} from 'react';
import _ from 'lodash';
import Icon from '../Icon';
import React from 'react';

import styles from './styles';
import styles from './styles/panel.module.css'

const Column = ({showIf=true, ...props}) => {
if (!showIf) {
return <div style={styles.empty} />;
}

return (
<div style={{...styles.column, ...props.style}}>
<div className={styles.column} style={{ ...props.style}}>
{props.children ||
<input style={{...styles.input, ...styles.integerInput}} value={props.value}
onChange={(e) => props.onChange(e.target.value)} />
<input
className={`${styles.input} ${styles.textInput}`}
value={props.value}
onChange={(e) => props.onChange(e.target.value)}
/>
}
{props.label &&
<div style={styles.inputHelper}>{props.label}</div>}
<div className={styles.inputHelper}>{props.label}</div>}
</div>
);
};
Expand Down
13 changes: 5 additions & 8 deletions src/designer/panels/Columns.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React, {Component} from 'react';
import _ from 'lodash';
import Icon from '../Icon';

import styles from './styles';
import React from 'react';
import styles from './styles/panel.module.css'

const Columns = ({showIf=true, ...props}) => {
if (!showIf) {
return <div style={styles.empty} />;
return <div className={styles.empty} />;
}
return (
<div style={styles.columns}>
<div style={styles.panelTitle}>{props.label}</div>
<div className={styles.columns}>
<div className={styles.panelTitle}>{props.label}</div>
{props.children}
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions src/designer/panels/ImagePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GridContainer } from './GridContainer'
import { NameItem } from './NameItem'
import { Switch } from './Switch'
import { useHasProperty } from '../hooks/useHasProperty'
import styles from './styles'
import styles from './styles/panel.module.css'

export const ImagePanel = ({ onChange, object }) => {
const [hasProperty] = useHasProperty(object)
Expand All @@ -28,7 +28,7 @@ export const ImagePanel = ({ onChange, object }) => {
}, [])

return (
<PropertyGroup object={object} showIf={_.has(object, 'xlinkHref')}>
<PropertyGroup className="react-designer-image-panel" object={object} showIf={_.has(object, 'xlinkHref')}>
<GridContainer>
{hasProperty('active') && (
<RowFlex>
Expand All @@ -43,7 +43,7 @@ export const ImagePanel = ({ onChange, object }) => {
<NameItem>Label:</NameItem>
<RowFlex>
<input
style={{ ...styles.input, ...styles.textInput }}
className={`${styles.input} ${styles.textInput}`}
onChange={(e) => onChange('label', e.target.value)}
value={object.label}
/>
Expand Down
17 changes: 3 additions & 14 deletions src/designer/panels/PanelList.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import React, {Component} from 'react';
import _ from 'lodash';
import { Portal } from 'react-portal';

import Icon from '../Icon';

import styles from './styles';
import PropertyGroup from './PropertyGroup';
import Button from './Button';
import SwitchState from './SwitchState';
import Columns from './Columns';
import Column from './Column';
import styleCss from './styles/panel.module.css'
import styles from './styles/panel.module.css'
import { NameItem } from './NameItem';
import { RowFlex } from './RowFlex';

Expand All @@ -19,12 +9,11 @@ class PanelList extends Component {
let {object, objectComponent, id, showPanels, show = false} = this.props;

return (
<div
<div
style={{
...styles.propertyPanel,
display: showPanels || show ? 'block' : 'none'
}}
className={styleCss.container}
className={`${styles.container} react-designer-panel-list`}
>
{showPanels && objectComponent.panels.map((Panel, i) => <Panel key={i} id={id} {...this.props} />)}
{show && !showPanels && (
Expand Down
13 changes: 5 additions & 8 deletions src/designer/panels/PropertyGroup.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React, {Component} from 'react';
import _ from 'lodash';
import Icon from '../Icon';
import React from 'react';
import styles from './styles/panel.module.css'

import styles from './styles';

const PropertyGroup = ({showIf=true, ...props}) => {
const PropertyGroup = ({showIf=true , className, ...props}) => {
if (!showIf) {
return <div style={styles.empty} />;
return <div className={styles.empty} />;
}
return (
<div style={styles.propertyGroup}>
<div className={`${styles.group} react-designer-panel-group ${className || ''}`}>
{props.children}
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion src/designer/panels/RadioGroup/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react'
import style from './radioGroup.module.css'



export const RadioGroup = ({ name, defaultValue, onChange, children }) => {
return (
<div className={style.group}>
<div className={`${style.group} react-designer-radio-group`}>
{React.Children.toArray(children).map((child) => {
return React.cloneElement(child, { name, defaultValue, onChange })
})}
Expand Down
6 changes: 2 additions & 4 deletions src/designer/panels/RadioInput/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const RadioInput = ({
value,
defaultValue,
onChange,
icon,
label,
}) => {
const handleChange = (event) => {
Expand All @@ -16,16 +15,15 @@ export const RadioInput = ({
const checked = value === defaultValue

return (
<label className={style.container}>
<label className={`${style.container} react-designer-radio-label`}>
<input
className={icon ? style.check : ''}
className='react-designer-radio-input'
name={name}
type="radio"
value={value}
defaultChecked={checked}
onChange={handleChange}
/>
{icon && icon}
{label && <span>{label}</span>}
</label>
)
Expand Down
7 changes: 1 addition & 6 deletions src/designer/panels/SizePanel.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import React, { Component } from 'react'
import _ from 'lodash'

import Icon from '../Icon'

import styles from './styles'
import PropertyGroup from './PropertyGroup'
import Button from './Button'
import SwitchState from './SwitchState'
import Columns from './Columns'
import Column from './Column'

export class SizePanel extends Component {
render() {
let { object } = this.props
return (
<PropertyGroup object={object}>
<PropertyGroup className="react-designer-size-panel" object={object}>
{_.has(object, 'width', 'height') && (
<Columns label="Size">
<Column
Expand Down
159 changes: 78 additions & 81 deletions src/designer/panels/StylePanel.jsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,85 @@
import React, { Component } from 'react'
import _ from 'lodash'

import Icon from '../Icon'

import styles from './styles'
import React from 'react'
import PropertyGroup from './PropertyGroup'
import Button from './Button'
import SwitchState from './SwitchState'
import Columns from './Columns'
import Column from './Column'
import ColorInput from './ColorInput'

export class StylePanel extends Component {
modes = [
'normal',
'multiply',
'screen',
'overlay',
'darken',
'lighten',
'color-dodge',
'color-burn',
'hard-light',
'soft-light',
'difference',
'exclusion',
'hue',
'saturation',
'color',
'luminosity',
]
import styles from './styles/panel.module.css'

const modes = [
'normal',
'multiply',
'screen',
'overlay',
'darken',
'lighten',
'color-dodge',
'color-burn',
'hard-light',
'soft-light',
'difference',
'exclusion',
'hue',
'saturation',
'color',
'luminosity',
]

export const StylePanel = (props) => {
const object = props?.object

render() {
let { object } = this.props
return (
<PropertyGroup>
<Columns label="Fill" showIf={_.has(object, 'fill')}>
<Column>
<ColorInput
value={object.fill}
onChange={this.props.onChange.bind(this, 'fill')}
/>
</Column>
</Columns>
<Columns label="Stroke" showIf={_.has(object, 'stroke')}>
<Column>
<ColorInput
value={object.stroke}
onChange={this.props.onChange.bind(this, 'stroke')}
/>
</Column>
<Column label="width">
<input
style={{ ...styles.input, ...styles.integerInput, width: 30 }}
onChange={(e) =>
this.props.onChange('strokeWidth', e.target.value)
}
value={object.strokeWidth}
/>
</Column>
<Column showIf={_.has(object, 'radius')} label="radius">
<input
style={{ ...styles.input, ...styles.integerInput, width: 30 }}
onChange={(e) => this.props.onChange('radius', e.target.value)}
value={object.radius}
/>
</Column>
</Columns>
<Columns label="Blending">
<Column>
<select
style={styles.select}
value={object.blendmode}
onChange={(e) => this.props.onChange('blendmode', e.target.value)}
>
{this.modes.map((mode) => (
<option key={mode} value={mode}>
{mode}
</option>
))}
</select>
</Column>
</Columns>
</PropertyGroup>
)
}
return (
<PropertyGroup className="react-designer-style-panel">
<Columns label="Fill" showIf={object?.hasOwnProperty('fill')}>
<Column>
<ColorInput
value={object.fill}
onChange={props?.onChange?.bind?.(this, 'fill')}
/>
</Column>
</Columns>
<Columns label="Stroke" showIf={object?.hasOwnProperty('stroke')}>
<Column>
<ColorInput
value={object.stroke}
onChange={props?.onChange?.bind?.(this, 'stroke')}
/>
</Column>
<Column label="width">
<input
className={`${styles.input} ${styles.integerInput}`}
style={{ width: 30 }}
onChange={(e) =>
props?.onChange?.('strokeWidth', e.target.value)
}
value={object.strokeWidth}
/>
</Column>
<Column showIf={object?.hasOwnProperty('radius')} label="radius">
<input
className={`${styles.input} ${styles.integerInput}`}
style={{ width: 30 }}
onChange={(e) => props?.onChange?.('radius', e.target.value)}
value={object.radius}
/>
</Column>
</Columns>
<Columns label="Blending">
<Column>
<select
className={`${styles.select} react-designer-select`}
value={object.blendmode}
onChange={(e) => props?.onChange?.('blendmode', e.target.value)}
>
{modes.map((mode) => (
<option key={mode} value={mode}>
{mode}
</option>
))}
</select>
</Column>
</Columns>
</PropertyGroup>
)

}
6 changes: 2 additions & 4 deletions src/designer/panels/Switch/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import style from '../styles/check.module.css'
export const Switch = ({
text,
label,
icon,
defaultValue,
nextValue,
onChange,
Expand All @@ -16,15 +15,14 @@ export const Switch = ({
}

return (
<label htmlFor={label} className={style.container}>
<label htmlFor={label} className={`${style.container} react-designer-switch-label`}>
<input
className={icon ? style.check : ''}
className='react-designer-switch-input'
id={label}
type="checkbox"
onChange={handleCheck}
defaultChecked={defaultChecked}
/>
{icon && icon}
{text && <span>{text}</span>}
</label>
)
Expand Down
Loading

0 comments on commit 242de0c

Please sign in to comment.