forked from cardstack/boxel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplant-info.gts
131 lines (118 loc) · 3.61 KB
/
plant-info.gts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import {
FieldDef,
CardDef,
field,
containsMany,
StringField,
contains,
} from 'https://cardstack.com/base/card-api';
import { Component } from 'https://cardstack.com/base/card-api';
import { BoxelDropdown, Menu, Button } from '@cardstack/boxel-ui/components';
import { menuItemFunc } from '@cardstack/boxel-ui/helpers';
import { DropdownArrowDown } from '@cardstack/boxel-ui/icons';
class Edit extends Component<typeof DropdownField> {
<template>
<BoxelDropdown>
<:trigger as |bindings|>
<Button {{bindings}} class='dropdown-trigger'>
{{if @model.selectedValue @model.selectedValue 'Please select'}}
<DropdownArrowDown width='12px' height='12px' />
</Button>
</:trigger>
<:content as |dd|>
<Menu @closeMenu={{dd.close}} @items={{this.menuItems}} />
</:content>
</BoxelDropdown>
<style>
.dropdown-trigger {
padding: 0 15px;
min-width: 160px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
}
</style>
</template>
get menuItems() {
return this.args.model.options?.map((v: string) =>
menuItemFunc([v, () => (this.args.model.selectedValue = v)], {
selected: this.args.model.selectedValue === v,
}),
);
}
}
class DropdownField extends FieldDef {
static displayName = 'Dropdown Field';
@field options = containsMany(StringField);
@field selectedValue = contains(StringField);
static embedded = class Embedded extends Component<typeof this> {
<template>
<@fields.selectedValue />
</template>
};
static atom = class Atom extends Component<typeof this> {
<template>
<@fields.selectedValue />
</template>
};
static edit = Edit;
/*
static isolated = class Isolated extends Component<typeof this> {
<template></template>
};
*/
}
class LightRequirementDropdown extends DropdownField {
static displayName = 'Light Requirement';
static _options = ['Full Sun', 'Partial Sun', 'Partial Shade', 'Full Shade'];
@field options = containsMany(StringField, {
computeVia: function () {
return LightRequirementDropdown._options;
},
});
}
class ToxicityDropdown extends DropdownField {
static displayName = 'Toxicity';
static _options = ['Toxic', 'Non-Toxic', 'No Information'];
@field options = containsMany(StringField, {
computeVia: function () {
return ToxicityDropdown._options;
},
});
}
class SeasonsDropdown extends DropdownField {
static displayName = 'Season';
static _options = ['Spring', 'Summer', 'Fall', 'Winter'];
@field options = containsMany(StringField, {
computeVia: function () {
return SeasonsDropdown._options;
},
});
}
export class PlantInfo extends CardDef {
@field commonName = containsMany(StringField);
@field scientificName = contains(StringField);
@field lightRequirement = containsMany(LightRequirementDropdown);
@field toxicityForDogs = contains(ToxicityDropdown);
@field attracts = containsMany(StringField);
@field height = contains(StringField);
@field spacing = contains(StringField);
@field spread = contains(StringField);
@field seasonOfInterest = containsMany(SeasonsDropdown);
static displayName = 'Plant Info';
/*
static isolated = class Isolated extends Component<typeof this> {
<template></template>
}
static embedded = class Embedded extends Component<typeof this> {
<template></template>
}
static atom = class Atom extends Component<typeof this> {
<template></template>
}
static edit = class Edit extends Component<typeof this> {
<template></template>
}
*/
}