Skip to content

Commit

Permalink
Split the figure component out into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoetzer committed Oct 6, 2023
1 parent 4491c43 commit 4cb8b51
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
25 changes: 25 additions & 0 deletions components/image/figure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import PropTypes from 'prop-types';
import { StyledComponentContext } from '../styled-components-context';
import { InlineControlsStyleWrapper } from './styles';

export const Figure = (props) => {
const { style, children, ...rest } = props;

return (
<StyledComponentContext cacheKey="tenup-component-image">
<InlineControlsStyleWrapper {...style} {...rest}>
{children}
</InlineControlsStyleWrapper>
</StyledComponentContext>
);
};

Figure.defaultProps = {
style: {},
children: [],
};

Figure.propTypes = {
style: PropTypes.object,
children: PropTypes.array,
};
26 changes: 2 additions & 24 deletions components/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import PropTypes from 'prop-types';
/**
* Internal Dependencies
*/
import { StyledComponentContext } from '../styled-components-context';

import { Media, ImageContext } from './media';
import { Figure } from './figure';
import { InlineControls } from './inline-controls';
import { InlineControlsStyleWrapper } from './styles';
import { useMedia } from '../../hooks/use-media';

const ImageWrapper = (props) => {
Expand Down Expand Up @@ -154,25 +154,3 @@ ImageWrapper.propTypes = {
onRemove: PropTypes.func,
children: PropTypes.array,
};

const Figure = (props) => {
const { style, children, ...rest } = props;

return (
<StyledComponentContext cacheKey="tenup-component-image">
<InlineControlsStyleWrapper {...style} {...rest}>
{children}
</InlineControlsStyleWrapper>
</StyledComponentContext>
);
};

Figure.defaultProps = {
style: {},
children: [],
};

Figure.propTypes = {
style: PropTypes.object,
children: PropTypes.array,
};
9 changes: 6 additions & 3 deletions example/src/blocks/multiple-image-example/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function BlockEdit(props) {
className="example-image"
focalPoint={focalPoint1}
onChangeFocalPoint={(value) => setAttributes({focalPoint1: value})}
hasInlineControls={true} onRemove={() => setAttributes({image1: null})}
hasInlineControls={true}
onRemove={() => setAttributes({image1: null})}
isOptional={false}
/>

Expand All @@ -33,7 +34,8 @@ export function BlockEdit(props) {
className="example-image"
focalPoint={focalPoint2}
onChangeFocalPoint={(value) => setAttributes({focalPoint2: value})}
hasInlineControls={true} onRemove={() => setAttributes({image2: null})}
hasInlineControls={true}
onRemove={() => setAttributes({image2: null})}
/>

<Image
Expand All @@ -43,7 +45,8 @@ export function BlockEdit(props) {
className="example-image"
focalPoint={focalPoint3}
onChangeFocalPoint={(value) => setAttributes({focalPoint3: value})}
hasInlineControls={true} onRemove={() => setAttributes({image3: null})}
hasInlineControls={true}
onRemove={() => setAttributes({image3: null})}
/>
</div>
)
Expand Down

0 comments on commit 4cb8b51

Please sign in to comment.