This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add synthetic conditional component
- Loading branch information
Showing
11 changed files
with
200 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Pattern, PatternSlot } from '../../pattern'; | ||
import { BuiltInContext, BuiltInResult } from '../pattern-library'; | ||
import * as PatternProperty from '../../pattern-property'; | ||
import * as Types from '../../../types'; | ||
|
||
const PATTERN_CONTEXT_ID = 'synthetic:conditional'; | ||
const CONDITION_CONTEXT_ID = 'condition'; | ||
const TRUTHY_SLOT_CONTEXT_ID = 'truthy'; | ||
const FALSY_SLOT_CONTEXT_ID = 'falsy'; | ||
|
||
export const Conditional = (context: BuiltInContext): BuiltInResult => { | ||
const patternId = context.options.getGlobalPatternId(PATTERN_CONTEXT_ID); | ||
|
||
const properties = [ | ||
new PatternProperty.PatternBooleanProperty({ | ||
contextId: CONDITION_CONTEXT_ID, | ||
description: 'Show the "True" slot, disable to show the "False" slot', | ||
defaultValue: true, | ||
hidden: false, | ||
id: context.options.getGlobalPropertyId(patternId, CONDITION_CONTEXT_ID), | ||
label: 'Condition', | ||
origin: Types.PatternPropertyOrigin.BuiltIn, | ||
propertyName: 'condition', | ||
required: true | ||
}) | ||
]; | ||
|
||
const slots = [ | ||
new PatternSlot({ | ||
contextId: TRUTHY_SLOT_CONTEXT_ID, | ||
displayName: 'If True', | ||
description: '', | ||
example: '', | ||
hidden: false, | ||
propertyName: 'ifTrue', | ||
id: context.options.getGlobalSlotId(patternId, TRUTHY_SLOT_CONTEXT_ID), | ||
required: false, | ||
type: Types.SlotType.Property | ||
}), | ||
new PatternSlot({ | ||
contextId: FALSY_SLOT_CONTEXT_ID, | ||
displayName: 'If False', | ||
description: '', | ||
example: '', | ||
hidden: false, | ||
propertyName: 'ifFalse', | ||
id: context.options.getGlobalSlotId(patternId, FALSY_SLOT_CONTEXT_ID), | ||
required: false, | ||
type: Types.SlotType.Property | ||
}) | ||
]; | ||
|
||
return { | ||
pattern: new Pattern( | ||
{ | ||
contextId: PATTERN_CONTEXT_ID, | ||
description: 'for conditional rendering', | ||
exportName: 'default', | ||
id: patternId, | ||
name: 'Conditional', | ||
origin: Types.PatternOrigin.BuiltIn, | ||
propertyIds: properties.map(p => p.getId()), | ||
slots, | ||
type: Types.PatternType.SyntheticConditional | ||
}, | ||
context | ||
), | ||
properties | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.