Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

feat: extend placeholder builtin with size controls #481

Merged
merged 3 commits into from
May 30, 2018
Merged
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
48 changes: 48 additions & 0 deletions src/model/pattern-library/builtins/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import * as Types from '../../types';

const PATTERN_CONTEXT_ID = 'synthetic:placeholder';
const SRC_CONTEXT_ID = 'src';
const WIDTH_CONTEXT_ID = 'width';
const HEIGHT_CONTEXT_ID = 'height';
const MIN_WIDTH_CONTEXT_ID = 'min-width';
const MAX_WIDTH_CONTEXT_ID = 'max-width';
const MIN_HEIGHT_CONTEXT_ID = 'min-height';
const MAX_HEIGHT_CONTEXT_ID = 'max-height';

export const Placeholder = (context: BuiltInContext): BuiltInResult => {
const patternId = context.options.getGlobalPatternId(PATTERN_CONTEXT_ID);
Expand All @@ -16,6 +22,48 @@ export const Placeholder = (context: BuiltInContext): BuiltInResult => {
label: 'Source',
origin: Types.PatternPropertyOrigin.BuiltIn,
propertyName: 'src'
}),
new PatternProperty.PatternStringProperty({
contextId: WIDTH_CONTEXT_ID,
id: context.options.getGlobalPropertyId(patternId, WIDTH_CONTEXT_ID),
label: 'Width',
origin: Types.PatternPropertyOrigin.BuiltIn,
propertyName: 'width'
}),
new PatternProperty.PatternStringProperty({
contextId: HEIGHT_CONTEXT_ID,
id: context.options.getGlobalPropertyId(patternId, HEIGHT_CONTEXT_ID),
label: 'Height',
origin: Types.PatternPropertyOrigin.BuiltIn,
propertyName: 'height'
}),
new PatternProperty.PatternStringProperty({
contextId: MIN_WIDTH_CONTEXT_ID,
id: context.options.getGlobalPropertyId(patternId, MIN_WIDTH_CONTEXT_ID),
label: 'Min Width',
origin: Types.PatternPropertyOrigin.BuiltIn,
propertyName: 'minWidth'
}),
new PatternProperty.PatternStringProperty({
contextId: MIN_HEIGHT_CONTEXT_ID,
id: context.options.getGlobalPropertyId(patternId, MIN_HEIGHT_CONTEXT_ID),
label: 'Min Height',
origin: Types.PatternPropertyOrigin.BuiltIn,
propertyName: 'minHeight'
}),
new PatternProperty.PatternStringProperty({
contextId: MAX_WIDTH_CONTEXT_ID,
id: context.options.getGlobalPropertyId(patternId, MAX_WIDTH_CONTEXT_ID),
label: 'Max Width',
origin: Types.PatternPropertyOrigin.BuiltIn,
propertyName: 'maxWidth'
}),
new PatternProperty.PatternStringProperty({
contextId: MAX_HEIGHT_CONTEXT_ID,
id: context.options.getGlobalPropertyId(patternId, MAX_HEIGHT_CONTEXT_ID),
label: 'Max Height',
origin: Types.PatternPropertyOrigin.BuiltIn,
propertyName: 'maxHeight'
})
];

Expand Down
14 changes: 13 additions & 1 deletion src/preview/preview-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@ const SYNTHETICS = {
box: Box,
page: Page,
placeholder: props =>
props.src ? <img src={props.src} style={{ width: '100%', height: 'auto' }} /> : null,
props.src ? (
<img
src={props.src}
style={{
width: props.width,
height: props.height,
minWidth: props.minWidth,
maxWidth: props.maxWidth,
minHeight: props.minHeight,
maxHeight: props.maxHeight
}}
/>
) : null,
text: props => <span>{props.text}</span>
};

Expand Down