@getcortexlabs/mavis 0.1.0-alpha.1 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +4 -4
  2. package/dist/native/appearance.android.d.ts +4 -0
  3. package/dist/native/appearance.android.d.ts.map +1 -0
  4. package/dist/native/appearance.android.js +55 -0
  5. package/dist/native/appearance.android.js.map +1 -0
  6. package/dist/native/appearance.d.ts +4 -0
  7. package/dist/native/appearance.d.ts.map +1 -0
  8. package/dist/native/appearance.js +31 -0
  9. package/dist/native/appearance.js.map +1 -0
  10. package/dist/native/box.android.d.ts +5 -0
  11. package/dist/native/box.android.d.ts.map +1 -0
  12. package/dist/native/box.android.js +7 -0
  13. package/dist/native/box.android.js.map +1 -0
  14. package/dist/native/box.d.ts +2 -0
  15. package/dist/native/box.d.ts.map +1 -0
  16. package/dist/native/box.ios.d.ts +6 -0
  17. package/dist/native/box.ios.d.ts.map +1 -0
  18. package/dist/native/box.ios.js +12 -0
  19. package/dist/native/box.ios.js.map +1 -0
  20. package/dist/native/box.js +3 -0
  21. package/dist/native/box.js.map +1 -0
  22. package/dist/native/button.android.d.ts +11 -0
  23. package/dist/native/button.android.d.ts.map +1 -0
  24. package/dist/native/button.android.js +31 -0
  25. package/dist/native/button.android.js.map +1 -0
  26. package/dist/native/flex-children.d.ts +4 -0
  27. package/dist/native/flex-children.d.ts.map +1 -0
  28. package/dist/native/flex-children.js +12 -0
  29. package/dist/native/flex-children.js.map +1 -0
  30. package/dist/native/flex-layout.android.d.ts +3 -1
  31. package/dist/native/flex-layout.android.d.ts.map +1 -1
  32. package/dist/native/flex-layout.android.js +9 -0
  33. package/dist/native/flex-layout.android.js.map +1 -1
  34. package/dist/native/flex-layout.ios.d.ts +4 -1
  35. package/dist/native/flex-layout.ios.d.ts.map +1 -1
  36. package/dist/native/flex-layout.ios.js +28 -0
  37. package/dist/native/flex-layout.ios.js.map +1 -1
  38. package/dist/vue/components/MButton.d.ts +26 -8
  39. package/dist/vue/components/MButton.d.ts.map +1 -1
  40. package/dist/vue/components/MButton.js +25 -6
  41. package/dist/vue/components/MButton.js.map +1 -1
  42. package/dist/vue/components/MCard.d.ts +1 -1
  43. package/dist/vue/components/MIcon.d.ts +55 -0
  44. package/dist/vue/components/MIcon.d.ts.map +1 -0
  45. package/dist/vue/components/MIcon.js +34 -0
  46. package/dist/vue/components/MIcon.js.map +1 -0
  47. package/dist/vue/components/MInput.d.ts +31 -13
  48. package/dist/vue/components/MInput.d.ts.map +1 -1
  49. package/dist/vue/components/MInput.js +26 -5
  50. package/dist/vue/components/MInput.js.map +1 -1
  51. package/dist/vue/components/MReveal.d.ts +2 -2
  52. package/dist/vue/components/MReveal.js +1 -1
  53. package/dist/vue/components/MReveal.js.map +1 -1
  54. package/dist/vue/components/MScreen.d.ts +1 -1
  55. package/dist/vue/components/MScreen.js +1 -1
  56. package/dist/vue/components/MScreen.js.map +1 -1
  57. package/dist/vue/components/MSlider.js +1 -1
  58. package/dist/vue/components/MSlider.js.map +1 -1
  59. package/dist/vue/components/MText.d.ts +2 -2
  60. package/dist/vue/components/MText.js +1 -1
  61. package/dist/vue/components/MText.js.map +1 -1
  62. package/dist/vue/components/layout.d.ts +5 -5
  63. package/dist/vue/components/layout.d.ts.map +1 -1
  64. package/dist/vue/components/layout.js +4 -2
  65. package/dist/vue/components/layout.js.map +1 -1
  66. package/dist/vue/index.d.ts +7 -7
  67. package/dist/vue/index.d.ts.map +1 -1
  68. package/dist/vue/index.js +9 -5
  69. package/dist/vue/index.js.map +1 -1
  70. package/fonts/LICENSE +45 -0
  71. package/fonts/lucide.ttf +0 -0
  72. package/package.json +3 -2
  73. package/platforms/android/java/com/mavis/ui/Box.java +30 -0
  74. package/platforms/android/java/com/mavis/ui/FlexLayout.java +21 -0
  75. package/src/native/appearance.android.ts +75 -0
  76. package/src/native/appearance.ts +33 -0
  77. package/src/native/box.android.ts +11 -0
  78. package/src/native/box.ios.ts +14 -0
  79. package/src/native/box.ts +2 -0
  80. package/src/native/button.android.ts +38 -0
  81. package/src/native/flex-children.ts +12 -0
  82. package/src/native/flex-layout.android.ts +12 -1
  83. package/src/native/flex-layout.ios.ts +35 -1
  84. package/src/vue/components/MButton.ts +32 -5
  85. package/src/vue/components/MIcon.ts +41 -0
  86. package/src/vue/components/MInput.ts +27 -4
  87. package/src/vue/components/MReveal.ts +1 -1
  88. package/src/vue/components/MScreen.ts +1 -1
  89. package/src/vue/components/MSlider.ts +1 -1
  90. package/src/vue/components/MText.ts +1 -1
  91. package/src/vue/components/layout.ts +4 -2
  92. package/src/vue/index.ts +22 -8
@@ -6,10 +6,16 @@ import {
6
6
  textContent,
7
7
  useDefaultShrink,
8
8
  } from '@getcortexlabs/mavis-core/vue'
9
- import { nonNegative } from '@getcortexlabs/mavis-core'
9
+ import {
10
+ nonNegative,
11
+ iconGlyph,
12
+ iconFontFamily,
13
+ iconSizes,
14
+ checkIconOnly,
15
+ } from '@getcortexlabs/mavis-core'
10
16
  import { isAndroid } from '@nativescript/core'
11
17
  import { usePressFeedback } from '../use-press.js'
12
- import { MavisButton } from '../../native/button.js'
18
+ import { MavisButton } from '../../native/button'
13
19
  import { useNativeViewAttrs } from '../accessibility.js'
14
20
 
15
21
  registerElement('MavisButton', () => MavisButton)
@@ -32,19 +38,30 @@ export const MButton = defineComponent({
32
38
  const text = props.loading
33
39
  ? props.loadingText
34
40
  : (props.text ?? textContent(slots.default?.()))
41
+ const hasIcon = Boolean(props.icon || props.trailingIcon)
42
+ checkIconOnly(text, hasIcon, props.accessibilityLabel)
43
+ const iconSize = iconSizes[props.size]
44
+ const minHeight = Math.max(size.height, isAndroid ? 48 : 44)
45
+ const paddingX = hasIcon && !text ? Math.round((minHeight - iconSize) / 2) : size.padding
46
+ const span = (name: typeof props.icon) =>
47
+ name
48
+ ? h('Span', { text: iconGlyph(name), fontFamily: iconFontFamily, fontSize: iconSize })
49
+ : null
35
50
  return h(
36
51
  'MavisButton',
37
52
  mergeProps(
38
53
  {
39
54
  // Android builds the accessible description from the current text.
40
55
  // Apply it before updating the label/value during the same render.
56
+ // Core ignores text while spans render, so the plain text keeps the description short.
41
57
  text,
58
+ ...(hasIcon ? {} : { formattedText: null }),
42
59
  textWrap: true,
43
60
  iosAccessibilityAdjustsFontSize: true,
44
61
  style: {
45
- minHeight: Math.max(size.height, isAndroid ? 48 : 44),
46
- paddingLeft: size.padding,
47
- paddingRight: size.padding,
62
+ minHeight,
63
+ paddingLeft: paddingX,
64
+ paddingRight: paddingX,
48
65
  paddingTop: 12,
49
66
  paddingBottom: 12,
50
67
  fontSize: size.fontSize,
@@ -83,6 +100,16 @@ export const MButton = defineComponent({
83
100
  },
84
101
  },
85
102
  ),
103
+ hasIcon
104
+ ? [
105
+ h('FormattedString', {}, [
106
+ span(props.icon),
107
+ text ? h('Span', { text: props.icon ? ` ${text}` : text }) : null,
108
+ props.trailingIcon && text ? h('Span', { text: ' ' }) : null,
109
+ span(props.trailingIcon),
110
+ ]),
111
+ ]
112
+ : undefined,
86
113
  )
87
114
  }
88
115
  },
@@ -0,0 +1,41 @@
1
+ import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vue'
2
+ import { iconProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
3
+ import { iconFontFamily, iconGlyph, resolveIconSize } from '@getcortexlabs/mavis-core'
4
+ import { MavisLabel } from '../../native/label'
5
+
6
+ registerElement('MavisIcon', () => MavisLabel)
7
+
8
+ export const MIcon = defineComponent({
9
+ name: 'MIcon',
10
+ inheritAttrs: false,
11
+ props: iconProps,
12
+ setup(props, { attrs }) {
13
+ const { theme } = useMavisTheme()
14
+ return () => {
15
+ const size = resolveIconSize(props.size)
16
+ return h(
17
+ 'MavisIcon',
18
+ mergeProps(
19
+ {
20
+ id: props.id,
21
+ text: iconGlyph(props.name),
22
+ textWrap: false,
23
+ accessible: Boolean(props.label),
24
+ accessibilityHidden: !props.label,
25
+ accessibilityRole: 'image',
26
+ accessibilityLabel: props.label,
27
+ style: {
28
+ fontFamily: iconFontFamily,
29
+ fontSize: size,
30
+ color: theme.value.colors[props.tone],
31
+ textAlignment: 'center',
32
+ verticalAlignment: 'middle',
33
+ flexShrink: 0,
34
+ },
35
+ },
36
+ attrs,
37
+ ),
38
+ )
39
+ }
40
+ },
41
+ })
@@ -19,12 +19,14 @@ import {
19
19
  validateInput,
20
20
  nonNegative,
21
21
  resolveDimension,
22
+ iconSizes,
22
23
  type InputHandle,
23
24
  } from '@getcortexlabs/mavis-core'
24
25
  import type { EventData, PropertyChangeData, TextField, TextView } from '@nativescript/core'
25
- import { MavisTextField } from '../../native/text-field.js'
26
- import { MavisTextView } from '../../native/text-view.js'
26
+ import { MavisTextField } from '../../native/text-field'
27
+ import { MavisTextView } from '../../native/text-view'
27
28
  import { MText } from './MText.js'
29
+ import { MIcon } from './MIcon.js'
28
30
  import { useNativeViewAttrs } from '../accessibility.js'
29
31
 
30
32
  registerElement('MavisTextField', () => MavisTextField)
@@ -67,6 +69,25 @@ export const MInput = defineComponent({
67
69
  const text = props.type === 'text' || props.type === 'search'
68
70
  const capitalize = props.autocapitalize ?? (text ? 'sentences' : 'none')
69
71
  const border = props.error ? colors.danger : focused.value ? colors.primary : colors.border
72
+ const inset = 16 + iconSizes.md + 10
73
+ // Icons sit over the editor box and let touches through to it.
74
+ const icon = (name: typeof props.icon, trailing: boolean) =>
75
+ name
76
+ ? h(MIcon, {
77
+ name,
78
+ size: 'md',
79
+ tone: props.error ? 'danger' : 'muted',
80
+ row: 1,
81
+ isUserInteractionEnabled: false,
82
+ style: {
83
+ horizontalAlignment: trailing ? 'right' : 'left',
84
+ verticalAlignment: props.multiline ? 'top' : 'middle',
85
+ marginLeft: trailing ? 0 : 16,
86
+ marginRight: trailing ? 16 : 0,
87
+ marginTop: space.sm + (props.multiline ? 14 : 0),
88
+ },
89
+ })
90
+ : null
70
91
  return h(
71
92
  'GridLayout',
72
93
  mergeProps(
@@ -124,8 +145,8 @@ export const MInput = defineComponent({
124
145
  minWidth: 0,
125
146
  minHeight: props.multiline ? props.rows * 24 + 30 : control.md.height,
126
147
  padding: 14,
127
- paddingLeft: 16,
128
- paddingRight: 16,
148
+ paddingLeft: props.icon ? inset : 16,
149
+ paddingRight: props.trailingIcon ? inset : 16,
129
150
  margin: 0,
130
151
  marginTop: space.sm,
131
152
  fontSize: typography.body.fontSize,
@@ -159,6 +180,8 @@ export const MInput = defineComponent({
159
180
  emit('submit', field.text ?? '')
160
181
  },
161
182
  }),
183
+ icon(props.icon, false),
184
+ icon(props.trailingIcon, true),
162
185
  message
163
186
  ? h(MText, {
164
187
  row: 2,
@@ -4,7 +4,7 @@ import { revealProps } from '@getcortexlabs/mavis-core/vue'
4
4
  import { MColumn } from './layout.js'
5
5
  import { isAndroid, type View } from '@nativescript/core'
6
6
  import { focusedView } from '../accessibility.js'
7
- import { notifyAccessibilityLayout } from '../../native/accessibility-layout.js'
7
+ import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
8
8
 
9
9
  export const MReveal = defineComponent({
10
10
  name: 'MReveal',
@@ -1,7 +1,7 @@
1
1
  import { defineComponent, h, mergeProps, provide, registerElement } from 'nativescript-vue'
2
2
  import { screenProps, useMavisTheme, layoutDirection } from '@getcortexlabs/mavis-core/vue'
3
3
  import { MColumn } from './layout.js'
4
- import { MavisScreenScroll } from '../../native/screen-scroll.js'
4
+ import { MavisScreenScroll } from '../../native/screen-scroll'
5
5
  import { useNativeViewAttrs } from '../accessibility.js'
6
6
 
7
7
  registerElement('MavisScreenScroll', () => MavisScreenScroll, {
@@ -2,7 +2,7 @@ import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vu
2
2
  import { sliderProps, useMavisTheme, sliderEmits } from '@getcortexlabs/mavis-core/vue'
3
3
  import { sliderScale } from '@getcortexlabs/mavis-core'
4
4
  import { isAndroid, type PropertyChangeData } from '@nativescript/core'
5
- import { MavisSlider } from '../../native/slider.js'
5
+ import { MavisSlider } from '../../native/slider'
6
6
  import { useNativeViewAttrs } from '../accessibility.js'
7
7
 
8
8
  registerElement('MavisSlider', () => MavisSlider)
@@ -6,7 +6,7 @@ import {
6
6
  useDefaultShrink,
7
7
  } from '@getcortexlabs/mavis-core/vue'
8
8
  import { nonNegative } from '@getcortexlabs/mavis-core'
9
- import { MavisLabel } from '../../native/label.js'
9
+ import { MavisLabel } from '../../native/label'
10
10
  import { useNativeViewAttrs } from '../accessibility.js'
11
11
 
12
12
  registerElement('MavisLabel', () => MavisLabel)
@@ -8,7 +8,8 @@ import {
8
8
  import { defineComponent, h, mergeProps, provide, registerElement } from 'nativescript-vue'
9
9
  import { resolveSpace } from '@getcortexlabs/mavis-core'
10
10
  import { boxProps, boxStyle } from '../props.js'
11
- import { MavisFlexLayout } from '../../native/flex-layout.js'
11
+ import { MavisFlexLayout } from '../../native/flex-layout'
12
+ import { MavisBox } from '../../native/box'
12
13
  import { useNativeViewAttrs } from '../accessibility.js'
13
14
 
14
15
  export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
@@ -17,6 +18,7 @@ registerElement('MavisFlexLayout', () => MavisFlexLayout, {
17
18
  // NSVViewFlags.LAYOUT_VIEW is a const enum with no runtime export.
18
19
  viewFlags: 4,
19
20
  })
21
+ registerElement('MavisBox', () => MavisBox, { viewFlags: 4 })
20
22
 
21
23
  const alignment = {
22
24
  start: 'flex-start',
@@ -79,7 +81,7 @@ export const MBox = defineComponent({
79
81
  const shrink = useDefaultShrink()
80
82
  return () =>
81
83
  h(
82
- 'GridLayout',
84
+ 'MavisBox',
83
85
  mergeProps({ style: boxStyle(theme.value, props, shrink) }, nativeAttrs(), attrs),
84
86
  slots.default?.(),
85
87
  )
package/src/vue/index.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import type { App } from 'nativescript-vue'
2
- import { mavis } from '@getcortexlabs/mavis-core'
3
- import type { MavisTheme } from '@getcortexlabs/mavis-core'
4
- import { createThemeContext, themeKey } from '@getcortexlabs/mavis-core/vue'
2
+ import {
3
+ createThemeContext,
4
+ themeKey,
5
+ type ThemeContextOptions,
6
+ } from '@getcortexlabs/mavis-core/vue'
7
+ import { systemAppearance } from '../native/appearance'
5
8
  import { MScreen } from './components/MScreen.js'
6
9
  import { MBox, MRow, MColumn } from './components/layout.js'
7
10
  import { MCard } from './components/MCard.js'
@@ -9,19 +12,29 @@ import { MText } from './components/MText.js'
9
12
  import { MButton } from './components/MButton.js'
10
13
  import { MSlider } from './components/MSlider.js'
11
14
  import { MInput } from './components/MInput.js'
15
+ import { MIcon } from './components/MIcon.js'
12
16
  import { MReveal } from './components/MReveal.js'
13
17
 
14
- export { MScreen, MBox, MRow, MColumn, MCard, MText, MButton, MSlider, MInput, MReveal }
18
+ export { MScreen, MBox, MRow, MColumn, MCard, MText, MButton, MSlider, MInput, MIcon, MReveal }
15
19
  export { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
16
- export type { MavisThemeContext } from '@getcortexlabs/mavis-core/vue'
20
+ export type {
21
+ MavisThemeContext,
22
+ Appearance,
23
+ AppearanceMode,
24
+ AppearanceSource,
25
+ } from '@getcortexlabs/mavis-core/vue'
17
26
  export type { Align, Justify } from './components/layout.js'
18
27
  export type {} from '@getcortexlabs/mavis-core/vue'
19
28
 
20
- /** Create one plugin per application. Vue also resolves MButton as <m-button>. */
21
- export function createMavis(options: { theme?: MavisTheme } = {}) {
29
+ export type MavisOptions = Omit<ThemeContextOptions, 'source'>
30
+
31
+ /** Create one plugin per application; `system` appearance follows the device. Vue also resolves MButton as <m-button>. */
32
+ export function createMavis(options: MavisOptions = {}) {
22
33
  return {
23
34
  install(app: App) {
24
- app.provide(themeKey, createThemeContext(options.theme ?? mavis))
35
+ const context = createThemeContext({ ...options, source: systemAppearance() })
36
+ app.provide(themeKey, context)
37
+ app.onUnmount(() => context.dispose())
25
38
  for (const [name, component] of Object.entries({
26
39
  MScreen,
27
40
  MBox,
@@ -32,6 +45,7 @@ export function createMavis(options: { theme?: MavisTheme } = {}) {
32
45
  MButton,
33
46
  MSlider,
34
47
  MInput,
48
+ MIcon,
35
49
  MReveal,
36
50
  })) {
37
51
  app.component(name, component)