-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
178 lines (148 loc) · 3.97 KB
/
index.jsx
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import ulog from 'ulog'
import { h } from 'preact'
import defaultClasses from 'solids/list/classes'
import { createHelper } from '../style-classes'
import { Consumer } from '../theme'
const log = ulog('preact-solids:list')
export const List = (props = {}) => {
log('List', 'render', props)
const {
nonInteractive = false,
Component = nonInteractive ? 'nav' : 'ul',
dense = false,
twoLines = false,
avatars = false,
// list items
children,
// other attributes
...attributes
} = props
return (
<Consumer>{({ classes = {}, scope = 'local' }) => {
classes = { ...defaultClasses, ...classes }
let classNames = createHelper(classes, scope)
attributes.className = classNames(classes.list, {
[attributes.className || attributes.class]: attributes.className || attributes.class,
[classes.dense]: dense,
[classes.two_line]: twoLines,
[classes.avatars]: avatars,
[classes.non_interactive]: nonInteractive,
})
return (
<Component {...attributes}>
{children}
</Component>
);
}}</Consumer>
);
}
export default List;
export const Group = List.Group = (props = {}) => {
log('Group', 'render', props)
const {
Component = 'div',
// list items
children,
// other attributes
...attributes
} = props
return (
<Consumer>{({ classes = {}, scope = 'local' }) => {
classes = { ...defaultClasses, ...classes }
let classNames = createHelper(classes, scope)
attributes.className = classNames(classes.group, {
[attributes.className || attributes.class]: attributes.className || attributes.class,
})
return (
<Component {...attributes}>
{children}
</Component>
)
}}</Consumer>
)
}
export const Item = List.Item = ({
Component = 'li',
selected = false,
activated = false,
// material icon
icon = '',
// text
children,
// other attributes
...attributes
}) => (
<Consumer>{({ classes = {}, scope = 'local' }) => {
classes = { ...defaultClasses, ...classes }
let classNames = createHelper(classes, scope)
attributes.className = classNames(classes.item, {
[attributes.className || attributes.class]: attributes.className || attributes.class,
[classes.selected]: selected,
[classes.activated]: activated
})
return (
<Component role="option" {...attributes}>
{icon ? <i class={classNames(classes.graphic, 'material-icons')}>{icon}</i> : ''}
{children}
</Component>
)
}}</Consumer>
);
export const LinkItem = List.LinkItem = (props) => Item({ Component: props.Component || 'a', ...props })
export const ItemGraphic = List.ItemGraphic = (props = {}) => {
log('ItemGraphic', 'render', props)
const {
Component = 'span',
// list items
children,
// other attributes
...attributes
} = props
return (
<Consumer>{({ classes = {}, scope = 'local' }) => {
classes = { ...defaultClasses, ...classes }
let classNames = createHelper(classes, scope)
attributes.className = classNames(classes.graphic, {
[attributes.className || attributes.class]: attributes.className || attributes.class,
})
// children = children
return (
<Component {...attributes}>
{children && (children.length === 1) && (typeof children[0] === 'string') ? (
<i class="material-icons">{children}</i>
): (
children
)}
</Component>
)
}}</Consumer>
)
}
export const Divider = List.Divider = (props = {}) => {
log('Divider', 'render', props)
const {
Component = 'hr',
//
inset = false,
//
padded = false,
children,
// other attributes
...attributes
} = props
return (
<Consumer>{({ classes = {}, scope = 'local' }) => {
classes = { ...defaultClasses, ...classes };
let classNames = createHelper(classes, scope);
attributes.className = classNames(classes.divider, {
[attributes.className || attributes.class]: attributes.className || attributes.class,
[classes.inset]: inset,
[classes.padded]: padded
});
return (
<Component {...attributes}>{children}</Component>
)
}}</Consumer>
)
}
log('Initialized')