|
10 | 10 | import { onDestroy } from 'svelte'; |
11 | 11 | import { Template } from 'svelte-native/components'; |
12 | 12 | import IconButton from '~/components/common/IconButton.svelte'; |
13 | | - import ListItem from '~/components/common/ListItem.svelte'; |
14 | 13 | import { ListItem as IListItem } from '~/components/common/ListItem'; |
| 14 | + import ListItem from '~/components/common/ListItem.svelte'; |
| 15 | + import ListItemAutoSize from '~/components/common/ListItemAutoSize.svelte'; |
| 16 | + import SettingsSlider from '~/components/settings/SettingsSlider.svelte'; |
15 | 17 | import { lc } from '~/helpers/locale'; |
16 | | - import { colors } from '~/variables'; |
17 | | - import ListItemAutoSize from './ListItemAutoSize.svelte'; |
| 18 | + import { colors, fontScale, fonts } from '~/variables'; |
18 | 19 | export interface OptionType extends IListItem { |
19 | 20 | subtitle?: string; |
20 | 21 | isPick?: boolean; |
|
32 | 33 | export let borderRadius = 8; |
33 | 34 | export let rowHeight = null; |
34 | 35 | export let autofocus = false; |
| 36 | + export let estimatedItemSize = true; |
| 37 | + export let autoSize = false; |
| 38 | + export let isScrollEnabled = true; |
35 | 39 | export let width: string | number = '*'; |
36 | 40 | export let containerColumns: string = '*'; |
37 | 41 | export let autoSizeListItem: boolean = false; |
|
45 | 49 | export let onlyOneSelected = false; |
46 | 50 | export let currentlyCheckedItem = null; |
47 | 51 | export let onCheckBox: (item, value, e) => void = null; |
| 52 | + export let onChange: (item, value, e) => void = null; |
48 | 53 | export let onRightIconTap: (item, e) => void = null; |
49 | | - export let onLongPress: (item, e) => void = null; |
50 | 54 |
|
51 | 55 | export let titleProps: Partial<svelteNative.JSX.LabelAttributes> = {}; |
52 | 56 | export let titleHolderProps: Partial<svelteNative.JSX.StackLayoutAttributes> = {}; |
|
60 | 64 | let filter: string = null; |
61 | 65 |
|
62 | 66 | // technique for only specific properties to get updated on store change |
63 | | - $: ({ colorOutline } = $colors); |
| 67 | + $: ({ colorOutline, colorOnSurface } = $colors); |
64 | 68 |
|
65 | 69 | function updateFiltered(filter) { |
66 | 70 | if (filter) { |
|
105 | 109 | } catch (err) { |
106 | 110 | close(null); |
107 | 111 | } |
108 | | - } else if (item.type === 'checkbox') { |
| 112 | + } else if (item.type === 'checkbox' || item.type === 'switch') { |
109 | 113 | // we dont want duplicate events so let s timeout and see if we clicking diretly on the checkbox |
110 | 114 | const checkboxView: CheckBox = ((event.object as View).parent as View).getViewById('checkbox'); |
111 | 115 | clearCheckboxTimer(); |
|
176 | 180 | if (item.type) { |
177 | 181 | return item.type; |
178 | 182 | } |
| 183 | + if (autoSizeListItem && item.icon) { |
| 184 | + return 'lefticon'; |
| 185 | + } |
179 | 186 | if (item.rightIcon) { |
180 | 187 | return 'righticon'; |
181 | 188 | } |
|
227 | 234 | }} /> |
228 | 235 | </gridlayout> |
229 | 236 | {/if} |
230 | | - <collectionView {itemTemplateSelector} items={filteredOptions} row={2} {rowHeight} on:dataPopulated={onDataPopulated} ios:contentInsetAdjustmentBehavior={2}> |
| 237 | + <collectionView |
| 238 | + {autoSize} |
| 239 | + {estimatedItemSize} |
| 240 | + {isScrollEnabled} |
| 241 | + {itemTemplateSelector} |
| 242 | + items={filteredOptions} |
| 243 | + row={2} |
| 244 | + {rowHeight} |
| 245 | + on:dataPopulated={onDataPopulated} |
| 246 | + ios:contentInsetAdjustmentBehavior={2}> |
231 | 247 | <Template key="checkbox" let:item> |
232 | 248 | <svelte:component |
233 | 249 | this={component} |
234 | 250 | {borderRadius} |
235 | 251 | columns="auto,*,auto" |
236 | 252 | {fontSize} |
237 | 253 | {fontWeight} |
238 | | - {iconFontSize} |
| 254 | + iconFontSize={item.iconFontSize || iconFontSize} |
239 | 255 | {item} |
240 | 256 | mainCol={1} |
241 | | - {onLongPress} |
242 | 257 | showBottomLine={showBorders} |
243 | 258 | {subtitleProps} |
244 | 259 | {titleHolderProps} |
|
255 | 270 | on:checkedChange={(e) => onCheckedChanged(item, e)} /> |
256 | 271 | </svelte:component> |
257 | 272 | </Template> |
| 273 | + <Template key="switch" let:item> |
| 274 | + <svelte:component |
| 275 | + this={component} |
| 276 | + {borderRadius} |
| 277 | + columns="auto,*,auto" |
| 278 | + {fontSize} |
| 279 | + {fontWeight} |
| 280 | + iconFontSize={item.iconFontSize || iconFontSize} |
| 281 | + {item} |
| 282 | + mainCol={1} |
| 283 | + showBottomLine={showBorders} |
| 284 | + {subtitleProps} |
| 285 | + {titleHolderProps} |
| 286 | + {titleProps} |
| 287 | + {...templateProps} |
| 288 | + on:tap={(event) => onTap(item, event)}> |
| 289 | + <switch id="checkbox" checked={item.value} col={1} marginLeft={10} on:checkedChange={(e) => onCheckedChanged(item, e)} /> |
| 290 | + </svelte:component> |
| 291 | + </Template> |
258 | 292 | <Template key="righticon" let:item> |
259 | 293 | <svelte:component |
260 | 294 | this={component} |
261 | 295 | {borderRadius} |
262 | 296 | columns="*,auto" |
263 | 297 | {fontSize} |
264 | 298 | {fontWeight} |
265 | | - {iconFontSize} |
| 299 | + iconFontSize={item.iconFontSize || iconFontSize} |
266 | 300 | {item} |
267 | | - {onLongPress} |
268 | 301 | showBottomLine={showBorders} |
269 | 302 | {subtitleProps} |
270 | 303 | {titleHolderProps} |
|
274 | 307 | <mdbutton class="icon-btn" col={1} text={item.rightIcon} variant="text" on:tap={(event) => onRightTap(item, event)} /> |
275 | 308 | </svelte:component> |
276 | 309 | </Template> |
| 310 | + <Template key="lefticon" let:item> |
| 311 | + <svelte:component |
| 312 | + this={component} |
| 313 | + {borderRadius} |
| 314 | + columns="auto,*" |
| 315 | + {fontSize} |
| 316 | + {fontWeight} |
| 317 | + {item} |
| 318 | + mainCol={1} |
| 319 | + showBottomLine={showBorders} |
| 320 | + {subtitleProps} |
| 321 | + {titleHolderProps} |
| 322 | + {titleProps} |
| 323 | + {...templateProps} |
| 324 | + on:tap={(event) => onTap(item, event)}> |
| 325 | + <label |
| 326 | + col={0} |
| 327 | + color={item.color || colorOnSurface} |
| 328 | + fontFamily={$fonts.mdi} |
| 329 | + fontSize={(item.iconFontSize || iconFontSize) * $fontScale} |
| 330 | + paddingLeft="8" |
| 331 | + text={item.icon} |
| 332 | + verticalAlignment="center" |
| 333 | + width={iconFontSize * 2} /> |
| 334 | + </svelte:component> |
| 335 | + </Template> |
277 | 336 | <Template key="image" let:item> |
278 | 337 | <svelte:component |
279 | 338 | this={component} |
280 | 339 | {borderRadius} |
281 | 340 | columns="auto,*" |
282 | 341 | {fontSize} |
283 | 342 | {fontWeight} |
284 | | - {iconFontSize} |
| 343 | + iconFontSize={item.iconFontSize || iconFontSize} |
285 | 344 | {item} |
286 | 345 | mainCol={1} |
287 | | - {onLongPress} |
288 | 346 | showBottomLine={showBorders} |
289 | 347 | {subtitleProps} |
290 | 348 | title={item.name} |
291 | 349 | {titleHolderProps} |
292 | 350 | {titleProps} |
293 | 351 | {...templateProps} |
294 | 352 | on:tap={(event) => onTap(item, event)}> |
295 | | - <image borderRadius={4} col={0} colorMatrix={item.imageMatrix} marginBottom={5} marginRight={10} marginTop={5} src={item.image} /> |
| 353 | + <image borderRadius={4} col={0} marginBottom={5} marginRight={10} marginTop={5} src={item.image} /> |
296 | 354 | </svelte:component> |
297 | 355 | </Template> |
| 356 | + <Template key="slider" let:item> |
| 357 | + <SettingsSlider {...item} onChange={(value, event) => onChange?.(item, value, event)} /> |
| 358 | + </Template> |
298 | 359 | <Template let:item> |
299 | 360 | <svelte:component |
300 | 361 | this={component} |
301 | 362 | {borderRadius} |
302 | 363 | {fontSize} |
303 | 364 | {fontWeight} |
304 | | - {iconFontSize} |
| 365 | + iconFontSize={item.iconFontSize || iconFontSize} |
305 | 366 | {item} |
306 | | - {onLongPress} |
307 | 367 | showBottomLine={showBorders} |
308 | 368 | {subtitleProps} |
309 | 369 | {titleHolderProps} |
|
0 commit comments