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

Commit

Permalink
fix: support enums with string values
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Jun 1, 2018
1 parent 512fb16 commit 0368100
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,21 @@ function createEnumProperty(
label: args.symbol.name,
origin: 'user-provided',
options: enumDeclaration.members.map((enumMember, index) => {
const enumMemberOrdinal = enumMember.initializer
? parseInt(enumMember.initializer.getText(), 10)
: index;
const init = enumMember.initializer
? String(enumMember.initializer.getText())
: String(index);

const value = init.charAt(0) === '"' ? init.slice(1, -1) : init;

const name =
TypescriptUtils.getJsDocValueFromNode(enumMember, 'name') || enumMember.name.getText();

return {
contextId: String(enumMemberOrdinal),
contextId: init,
id: ctx.getEnumOptionId(enumId, name),
name,
ordinal: enumMemberOrdinal,
value: enumMemberOrdinal
ordinal: init,
value
};
}),
propertyName: args.symbol.name,
Expand Down
1 change: 0 additions & 1 deletion src/components/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const StyledButton = styled.button`
background: ${Color.White};
`
: ''};
${(props: ButtonProps) =>
typeof props.textColor !== 'undefined'
? `
Expand Down
22 changes: 11 additions & 11 deletions src/model/pattern-library/builtins/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,35 @@ export const Box = (context: BuiltInContext): BuiltInResult => {
id: context.options.getGloablEnumOptionId(alignId, 'flex-start'),
name: 'Start',
value: 'flex-start',
ordinal: 0
ordinal: '0'
}),
new PatternEnumPropertyOption({
contextId: 'flex-end',
id: context.options.getGloablEnumOptionId(alignId, 'flex-end'),
name: 'End',
value: 'flex-end',
ordinal: 1
ordinal: '1'
}),
new PatternEnumPropertyOption({
contextId: 'center',
id: defaultAlign,
name: 'Center',
value: 'center',
ordinal: 2
ordinal: '2'
}),
new PatternEnumPropertyOption({
contextId: 'stretch',
id: context.options.getGloablEnumOptionId(alignId, 'stretch'),
name: 'Stretch',
value: 'stretch',
ordinal: 3
ordinal: '3'
}),
new PatternEnumPropertyOption({
contextId: 'baseline',
id: context.options.getGloablEnumOptionId(alignId, 'baseline'),
name: 'Baseline',
value: 'baseline',
ordinal: 4
ordinal: '4'
})
]
}),
Expand All @@ -160,42 +160,42 @@ export const Box = (context: BuiltInContext): BuiltInResult => {
id: context.options.getGloablEnumOptionId(justifyId, 'flex-start'),
name: 'Start',
value: 'flex-start',
ordinal: 0
ordinal: '0'
}),
new PatternEnumPropertyOption({
contextId: 'flex-end',
id: context.options.getGloablEnumOptionId(justifyId, 'flex-end'),
name: 'End',
value: 'flex-end',
ordinal: 1
ordinal: '1'
}),
new PatternEnumPropertyOption({
contextId: 'center',
id: defaultJustify,
name: 'Center',
value: 'center',
ordinal: 2
ordinal: '2'
}),
new PatternEnumPropertyOption({
contextId: 'space-between',
id: context.options.getGloablEnumOptionId(justifyId, 'space-between'),
name: 'Space Between',
value: 'space-between',
ordinal: 3
ordinal: '3'
}),
new PatternEnumPropertyOption({
contextId: 'space-around',
id: context.options.getGloablEnumOptionId(justifyId, 'space-around'),
name: 'Space Around',
value: 'space-around',
ordinal: 4
ordinal: '4'
}),
new PatternEnumPropertyOption({
contextId: 'space-evenly',
id: context.options.getGloablEnumOptionId(justifyId, 'space-evenly'),
name: 'Space Evenly',
value: 'space-evenly',
ordinal: 5
ordinal: '5'
})
]
}),
Expand Down
2 changes: 1 addition & 1 deletion src/model/pattern-library/builtins/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Page = (context: BuiltInContext): BuiltInResult => {
contextId: language.value,
id: context.options.getGloablEnumOptionId(langEnumId, language.value),
name: language.name,
ordinal: index,
ordinal: '1',
value: language.value
})
);
Expand Down
10 changes: 5 additions & 5 deletions src/model/pattern-property/enum-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ export interface PatternEnumPropertyOptionInit {
contextId: string;
id: string;
name: string;
ordinal: number;
value: string | number;
ordinal: string;
value: string;
}

export class PatternEnumPropertyOption {
@Mobx.observable private contextId: string;
@Mobx.observable private id: string;
@Mobx.observable private name: string;
@Mobx.observable private ordinal: number;
@Mobx.observable private value: string | number;
@Mobx.observable private ordinal: string;
@Mobx.observable private value: string;

public constructor(init: PatternEnumPropertyOptionInit) {
this.id = init.id;
Expand All @@ -157,7 +157,7 @@ export class PatternEnumPropertyOption {
return this.name;
}

public getOrdinal(): number {
public getOrdinal(): string {
return this.ordinal;
}

Expand Down
4 changes: 2 additions & 2 deletions src/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export interface SerializedEnumOption {
contextId: string;
id: string;
name: string;
ordinal: number;
value: string | number;
ordinal: string;
value: string;
}

export interface SerializedPatternNumberArrayProperty extends SerializedPropertyBase {
Expand Down

0 comments on commit 0368100

Please sign in to comment.