@vonage/vivid-react 2.10.47 → 2.10.56

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 (286) hide show
  1. package/.storybook/main.js +11 -0
  2. package/.storybook/preview.js +3 -0
  3. package/README.md +59 -59
  4. package/babel.config.js +38 -0
  5. package/package.json +58 -58
  6. package/rollup.config.js +30 -0
  7. package/scripts/cli.js +28 -0
  8. package/scripts/generateWrappers/consts.js +226 -0
  9. package/scripts/generateWrappers/generator.js +130 -0
  10. package/scripts/generateWrappers/helpers/generator.js +18 -0
  11. package/scripts/generateWrappers/helpers/generator.test.js +56 -0
  12. package/scripts/generateWrappers/index.js +0 -0
  13. package/scripts/generateWrappers/prop.types.js +86 -0
  14. package/scripts/generateWrappers/templates/js/index.tmpl +2 -0
  15. package/scripts/generateWrappers/templates/js/react-component.tmpl +30 -0
  16. package/scripts/generateWrappers/templates/js/stories.tmpl +18 -0
  17. package/scripts/generateWrappers/templates/templates.js +36 -0
  18. package/scripts/generateWrappers/templates/ts/index.tmpl +2 -0
  19. package/scripts/generateWrappers/templates/ts/react-component.tmpl +28 -0
  20. package/scripts/generateWrappers/utils.js +226 -0
  21. package/scripts/generateWrappers/utils.test.js +71 -0
  22. package/scripts/updateDocs.js +42 -0
  23. package/scripts/updateVividPackages.js +81 -0
  24. package/src/dataGrid/index.js +15 -0
  25. package/src/index.js +3 -0
  26. package/src/initialization/initVivid.js +24 -0
  27. package/src/patches/VwcCard/index.js +2 -0
  28. package/src/patches/VwcCard/vwcCardHeadingCrop.js +28 -0
  29. package/src/patches/VwcCard/vwcCardWithMenu.js +14 -0
  30. package/src/patches/index.js +6 -0
  31. package/src/patches/vwcDataGrid.js +26 -0
  32. package/src/patches/vwcNoteContentOverflow.js +20 -0
  33. package/src/patches/vwcSetAttributeValue.js +12 -0
  34. package/src/patches/vwcSnackBarHtmlMessage.js +21 -0
  35. package/src/patches/vwcTooltip.js +46 -0
  36. package/stories/VwcAccordion/VwcAccordion.stories.jsx +18 -0
  37. package/stories/VwcActionGroup/VwcActionGroup.stories.jsx +18 -0
  38. package/stories/VwcBadge/VwcBadge.stories.jsx +18 -0
  39. package/stories/VwcBanner/VwcBanner.stories.jsx +18 -0
  40. package/stories/VwcButton/VwcButton.stories.jsx +18 -0
  41. package/stories/VwcButtonToggleGroup/VwcButtonToggleGroup.stories.jsx +47 -0
  42. package/stories/VwcCalendar/VwcCalendar.stories.jsx +18 -0
  43. package/stories/VwcCalendarEvent/VwcCalendarEvent.stories.jsx +18 -0
  44. package/stories/VwcCard/VwcCard.stories.jsx +90 -0
  45. package/stories/VwcCarousel/VwcCarousel.stories.jsx +18 -0
  46. package/stories/VwcCarouselItem/VwcCarouselItem.stories.jsx +18 -0
  47. package/stories/VwcCheckListItem/VwcCheckListItem.stories.jsx +18 -0
  48. package/stories/VwcCheckbox/VwcCheckbox.stories.jsx +18 -0
  49. package/stories/VwcChip/VwcChip.stories.jsx +18 -0
  50. package/stories/VwcChipSet/VwcChipSet.stories.jsx +38 -0
  51. package/stories/VwcCircularProgress/VwcCircularProgress.stories.jsx +18 -0
  52. package/stories/VwcDataGrid/VwcDataGrid.stories.jsx +109 -0
  53. package/stories/VwcDataGridColumn/VwcDataGridColumn.stories.jsx +18 -0
  54. package/stories/VwcDatepicker/VwcDatepicker.stories.jsx +18 -0
  55. package/stories/VwcDialog/VwcDialog.stories.jsx +18 -0
  56. package/stories/VwcDrawer/VwcDrawer.stories.jsx +18 -0
  57. package/stories/VwcDropdown/VwcDropdown.stories.jsx +18 -0
  58. package/stories/VwcElevation/VwcElevation.stories.jsx +18 -0
  59. package/stories/VwcEmptyState/VwcEmptyState.stories.jsx +18 -0
  60. package/stories/VwcExpansionPanel/VwcExpansionPanel.stories.jsx +18 -0
  61. package/stories/VwcFab/VwcFab.stories.jsx +18 -0
  62. package/stories/VwcFilePicker/VwcFilePicker.stories.jsx +18 -0
  63. package/stories/VwcFormfield/VwcFormfield.stories.jsx +18 -0
  64. package/stories/VwcHelperMessage/VwcHelperMessage.stories.jsx +18 -0
  65. package/stories/VwcIcon/VwcIcon.stories.jsx +18 -0
  66. package/stories/VwcIconButton/VwcIconButton.stories.jsx +18 -0
  67. package/stories/VwcIconButtonToggle/VwcIconButtonToggle.stories.jsx +18 -0
  68. package/stories/VwcKeypad/VwcKeypad.stories.jsx +18 -0
  69. package/stories/VwcLayout/VwcLayout.stories.jsx +63 -0
  70. package/stories/VwcLinearProgress/VwcLinearProgress.stories.jsx +18 -0
  71. package/stories/VwcList/VwcList.stories.jsx +25 -0
  72. package/stories/VwcListExpansionPanel/VwcListExpansionPanel.stories.jsx +18 -0
  73. package/stories/VwcListItem/VwcListItem.stories.jsx +18 -0
  74. package/stories/VwcMenu/VwcMenu.stories.jsx +41 -0
  75. package/stories/VwcNotchedOutline/VwcNotchedOutline.stories.jsx +18 -0
  76. package/stories/VwcNote/VwcNote.stories.jsx +18 -0
  77. package/stories/VwcPagination/VwcPagination.stories.jsx +18 -0
  78. package/stories/VwcPopup/VwcPopup.stories.jsx +18 -0
  79. package/stories/VwcRadio/VwcRadio.stories.jsx +18 -0
  80. package/stories/VwcRadioListItem/VwcRadioListItem.stories.jsx +18 -0
  81. package/stories/VwcSchemeSelect/VwcSchemeSelect.stories.jsx +18 -0
  82. package/stories/VwcSelect/VwcSelect.stories.jsx +18 -0
  83. package/stories/VwcSideDrawer/VwcSideDrawer.stories.jsx +18 -0
  84. package/stories/VwcSlider/VwcSlider.stories.jsx +18 -0
  85. package/stories/VwcSnackbar/VwcSnackbar.stories.jsx +18 -0
  86. package/stories/VwcSurface/VwcSurface.stories.jsx +18 -0
  87. package/stories/VwcSwitch/VwcSwitch.stories.jsx +18 -0
  88. package/stories/VwcTab/VwcTab.stories.jsx +18 -0
  89. package/stories/VwcTabBar/VwcTabBar.stories.jsx +63 -0
  90. package/stories/VwcTag/VwcTag.stories.jsx +18 -0
  91. package/stories/VwcText/VwcText.stories.jsx +18 -0
  92. package/stories/VwcTextarea/VwcTextarea.stories.jsx +24 -0
  93. package/stories/VwcTextfield/VwcTextfield.stories.jsx +47 -0
  94. package/stories/VwcThemeSwitch/VwcThemeSwitch.stories.jsx +18 -0
  95. package/stories/VwcTooltip/VwcTooltip.stories.jsx +41 -0
  96. package/stories/VwcTopAppBar/VwcTopAppBar.stories.jsx +18 -0
  97. package/stories/VwcTopAppBarFixed/VwcTopAppBarFixed.stories.jsx +18 -0
  98. package/stories/patches/patches.stories.jsx +94 -0
  99. package/tsconfig.json +70 -0
  100. package/VwcAccordion/index.d.ts +0 -14
  101. package/VwcAccordion/index.js +0 -59
  102. package/VwcAccordion/package.json +0 -11
  103. package/VwcActionGroup/index.d.ts +0 -18
  104. package/VwcActionGroup/index.js +0 -90
  105. package/VwcActionGroup/package.json +0 -11
  106. package/VwcBadge/index.d.ts +0 -29
  107. package/VwcBadge/index.js +0 -154
  108. package/VwcBadge/package.json +0 -11
  109. package/VwcBanner/index.d.ts +0 -26
  110. package/VwcBanner/index.js +0 -91
  111. package/VwcBanner/package.json +0 -11
  112. package/VwcButton/index.d.ts +0 -55
  113. package/VwcButton/index.js +0 -240
  114. package/VwcButton/package.json +0 -11
  115. package/VwcButtonToggleGroup/index.d.ts +0 -25
  116. package/VwcButtonToggleGroup/index.js +0 -91
  117. package/VwcButtonToggleGroup/package.json +0 -11
  118. package/VwcCalendar/index.d.ts +0 -20
  119. package/VwcCalendar/index.js +0 -70
  120. package/VwcCalendar/package.json +0 -11
  121. package/VwcCalendarEvent/index.d.ts +0 -25
  122. package/VwcCalendarEvent/index.js +0 -81
  123. package/VwcCalendarEvent/package.json +0 -11
  124. package/VwcCard/index.d.ts +0 -23
  125. package/VwcCard/index.js +0 -76
  126. package/VwcCard/package.json +0 -11
  127. package/VwcCarousel/index.d.ts +0 -14
  128. package/VwcCarousel/index.js +0 -45
  129. package/VwcCarousel/package.json +0 -11
  130. package/VwcCarouselItem/index.d.ts +0 -14
  131. package/VwcCarouselItem/index.js +0 -49
  132. package/VwcCarouselItem/package.json +0 -11
  133. package/VwcCheckListItem/index.d.ts +0 -41
  134. package/VwcCheckListItem/index.js +0 -153
  135. package/VwcCheckListItem/package.json +0 -11
  136. package/VwcCheckbox/index.d.ts +0 -34
  137. package/VwcCheckbox/index.js +0 -126
  138. package/VwcCheckbox/package.json +0 -11
  139. package/VwcChip/index.d.ts +0 -31
  140. package/VwcChip/index.js +0 -106
  141. package/VwcChip/package.json +0 -11
  142. package/VwcChipSet/index.d.ts +0 -16
  143. package/VwcChipSet/index.js +0 -60
  144. package/VwcChipSet/package.json +0 -11
  145. package/VwcCircularProgress/index.d.ts +0 -24
  146. package/VwcCircularProgress/index.js +0 -84
  147. package/VwcCircularProgress/package.json +0 -11
  148. package/VwcDataGrid/index.d.ts +0 -33
  149. package/VwcDataGrid/index.js +0 -122
  150. package/VwcDataGrid/package.json +0 -11
  151. package/VwcDataGridColumn/index.d.ts +0 -43
  152. package/VwcDataGridColumn/index.js +0 -144
  153. package/VwcDataGridColumn/package.json +0 -11
  154. package/VwcDatepicker/index.d.ts +0 -120
  155. package/VwcDatepicker/index.js +0 -422
  156. package/VwcDatepicker/package.json +0 -11
  157. package/VwcDialog/index.d.ts +0 -40
  158. package/VwcDialog/index.js +0 -135
  159. package/VwcDialog/package.json +0 -11
  160. package/VwcDrawer/index.d.ts +0 -20
  161. package/VwcDrawer/index.js +0 -80
  162. package/VwcDrawer/package.json +0 -11
  163. package/VwcDropdown/index.d.ts +0 -61
  164. package/VwcDropdown/index.js +0 -221
  165. package/VwcDropdown/package.json +0 -11
  166. package/VwcElevation/index.d.ts +0 -14
  167. package/VwcElevation/index.js +0 -45
  168. package/VwcElevation/package.json +0 -11
  169. package/VwcEmptyState/index.d.ts +0 -18
  170. package/VwcEmptyState/index.js +0 -59
  171. package/VwcEmptyState/package.json +0 -11
  172. package/VwcExpansionPanel/index.d.ts +0 -34
  173. package/VwcExpansionPanel/index.js +0 -199
  174. package/VwcExpansionPanel/package.json +0 -11
  175. package/VwcFab/index.d.ts +0 -32
  176. package/VwcFab/index.js +0 -124
  177. package/VwcFab/package.json +0 -11
  178. package/VwcFilePicker/index.d.ts +0 -24
  179. package/VwcFilePicker/index.js +0 -88
  180. package/VwcFilePicker/package.json +0 -11
  181. package/VwcFormfield/index.d.ts +0 -20
  182. package/VwcFormfield/index.js +0 -70
  183. package/VwcFormfield/package.json +0 -11
  184. package/VwcHelperMessage/index.d.ts +0 -14
  185. package/VwcHelperMessage/index.js +0 -49
  186. package/VwcHelperMessage/package.json +0 -11
  187. package/VwcIcon/index.d.ts +0 -22
  188. package/VwcIcon/index.js +0 -102
  189. package/VwcIcon/package.json +0 -11
  190. package/VwcIconButton/index.d.ts +0 -31
  191. package/VwcIconButton/index.js +0 -111
  192. package/VwcIconButton/package.json +0 -11
  193. package/VwcIconButtonToggle/index.d.ts +0 -37
  194. package/VwcIconButtonToggle/index.js +0 -136
  195. package/VwcIconButtonToggle/package.json +0 -11
  196. package/VwcKeypad/index.d.ts +0 -31
  197. package/VwcKeypad/index.js +0 -176
  198. package/VwcKeypad/package.json +0 -11
  199. package/VwcLayout/index.d.ts +0 -20
  200. package/VwcLayout/index.js +0 -105
  201. package/VwcLayout/package.json +0 -11
  202. package/VwcLinearProgress/index.d.ts +0 -26
  203. package/VwcLinearProgress/index.js +0 -98
  204. package/VwcLinearProgress/package.json +0 -11
  205. package/VwcList/index.d.ts +0 -35
  206. package/VwcList/index.js +0 -146
  207. package/VwcList/package.json +0 -11
  208. package/VwcListExpansionPanel/index.d.ts +0 -19
  209. package/VwcListExpansionPanel/index.js +0 -68
  210. package/VwcListExpansionPanel/package.json +0 -11
  211. package/VwcListItem/index.d.ts +0 -42
  212. package/VwcListItem/index.js +0 -171
  213. package/VwcListItem/package.json +0 -11
  214. package/VwcMenu/index.d.ts +0 -53
  215. package/VwcMenu/index.js +0 -210
  216. package/VwcMenu/package.json +0 -11
  217. package/VwcNotchedOutline/index.d.ts +0 -17
  218. package/VwcNotchedOutline/index.js +0 -58
  219. package/VwcNotchedOutline/package.json +0 -11
  220. package/VwcNote/index.d.ts +0 -18
  221. package/VwcNote/index.js +0 -59
  222. package/VwcNote/package.json +0 -11
  223. package/VwcPagination/index.d.ts +0 -16
  224. package/VwcPagination/index.js +0 -52
  225. package/VwcPagination/package.json +0 -11
  226. package/VwcPopup/index.d.ts +0 -30
  227. package/VwcPopup/index.js +0 -147
  228. package/VwcPopup/package.json +0 -11
  229. package/VwcRadio/index.d.ts +0 -52
  230. package/VwcRadio/index.js +0 -149
  231. package/VwcRadio/package.json +0 -11
  232. package/VwcRadioListItem/index.d.ts +0 -41
  233. package/VwcRadioListItem/index.js +0 -148
  234. package/VwcRadioListItem/package.json +0 -11
  235. package/VwcSchemeSelect/index.d.ts +0 -14
  236. package/VwcSchemeSelect/index.js +0 -46
  237. package/VwcSchemeSelect/package.json +0 -11
  238. package/VwcSelect/index.d.ts +0 -60
  239. package/VwcSelect/index.js +0 -253
  240. package/VwcSelect/package.json +0 -11
  241. package/VwcSideDrawer/index.d.ts +0 -22
  242. package/VwcSideDrawer/index.js +0 -73
  243. package/VwcSideDrawer/package.json +0 -11
  244. package/VwcSlider/index.d.ts +0 -34
  245. package/VwcSlider/index.js +0 -129
  246. package/VwcSlider/package.json +0 -11
  247. package/VwcSnackbar/index.d.ts +0 -42
  248. package/VwcSnackbar/index.js +0 -138
  249. package/VwcSnackbar/package.json +0 -11
  250. package/VwcSurface/index.d.ts +0 -42
  251. package/VwcSurface/index.js +0 -145
  252. package/VwcSurface/package.json +0 -11
  253. package/VwcSwitch/index.d.ts +0 -27
  254. package/VwcSwitch/index.js +0 -114
  255. package/VwcSwitch/package.json +0 -11
  256. package/VwcTab/index.d.ts +0 -40
  257. package/VwcTab/index.js +0 -151
  258. package/VwcTab/package.json +0 -11
  259. package/VwcTabBar/index.d.ts +0 -15
  260. package/VwcTabBar/index.js +0 -55
  261. package/VwcTabBar/package.json +0 -11
  262. package/VwcTag/index.d.ts +0 -34
  263. package/VwcTag/index.js +0 -115
  264. package/VwcTag/package.json +0 -11
  265. package/VwcText/index.d.ts +0 -18
  266. package/VwcText/index.js +0 -83
  267. package/VwcText/package.json +0 -11
  268. package/VwcTextarea/index.d.ts +0 -93
  269. package/VwcTextarea/index.js +0 -331
  270. package/VwcTextarea/package.json +0 -11
  271. package/VwcTextfield/index.d.ts +0 -89
  272. package/VwcTextfield/index.js +0 -329
  273. package/VwcTextfield/package.json +0 -11
  274. package/VwcThemeSwitch/index.d.ts +0 -14
  275. package/VwcThemeSwitch/index.js +0 -57
  276. package/VwcThemeSwitch/package.json +0 -11
  277. package/VwcTooltip/index.d.ts +0 -22
  278. package/VwcTooltip/index.js +0 -105
  279. package/VwcTooltip/package.json +0 -11
  280. package/VwcTopAppBar/index.d.ts +0 -22
  281. package/VwcTopAppBar/index.js +0 -77
  282. package/VwcTopAppBar/package.json +0 -11
  283. package/VwcTopAppBarFixed/index.d.ts +0 -22
  284. package/VwcTopAppBarFixed/index.js +0 -88
  285. package/VwcTopAppBarFixed/package.json +0 -11
  286. package/index.js +0 -281
@@ -0,0 +1,71 @@
1
+ import { jest } from '@jest/globals'
2
+ import { getUniqueEvents } from './utils'
3
+
4
+ const { getVividPackageNames, event2PropName, prepareCompoundComponents } = require('./utils')
5
+
6
+ it('getVividPackageNames', () => {
7
+ const packageJson = {
8
+ dependencies: {
9
+ '@vonage/vwc-button': '0.1',
10
+ '@vonage/vwc-icon': '0.2',
11
+ '@nvm/vwc-badge': '0.2'
12
+ },
13
+ devDependencies: {
14
+ '@vonage/vwc-dropdown': '0.1',
15
+ '@vonage/component': '0.2'
16
+ },
17
+ otherDependencies: {
18
+ '@vonage/vwc-nav': '0.3'
19
+ }
20
+ }
21
+ const expectedList = [
22
+ '@vonage/vwc-button',
23
+ '@vonage/vwc-icon',
24
+ '@vonage/vwc-dropdown'
25
+ ]
26
+ expect(getVividPackageNames(packageJson)).toStrictEqual(expectedList)
27
+ })
28
+
29
+ it.each([
30
+ ['digit-added', 'onDigitAdded'],
31
+ ['userScrubRequest', 'onUserScrubRequest'],
32
+ ['vvd_scheme_select', 'onVvdSchemeSelect']
33
+ ])(`event2PropName should convert "%s" to "%s"`, (input, expected) => {
34
+ expect(event2PropName(input)).toStrictEqual(expected)
35
+ })
36
+
37
+ it('compound components', () => {
38
+ const template = jest.fn()
39
+ const config = {
40
+ CTA: {
41
+ connotation: 'cta',
42
+ layout: 'filled'
43
+ },
44
+ Alert: {
45
+ connotation: 'alert',
46
+ layout: 'filled'
47
+ }
48
+ }
49
+
50
+ prepareCompoundComponents('VwcButton', template, config)()
51
+
52
+ expect(template.mock.calls[0]).toEqual([
53
+ 'VwcButton',
54
+ 'CTA',
55
+ config.CTA
56
+ ])
57
+ expect(template.mock.calls[1]).toEqual([
58
+ 'VwcButton',
59
+ 'Alert',
60
+ config.Alert
61
+ ])
62
+ })
63
+
64
+ it('getUniqueEvents', () => {
65
+ const firstEvent = { name: 'non-unique', propName: 'replaced' }
66
+ const secondEvent = { name: 'non-unique', propName: 'targetPropName' }
67
+ const uniqueEvent = { name: 'unique', propName: 'onUnique' }
68
+ const events = [firstEvent, secondEvent, uniqueEvent]
69
+
70
+ expect(getUniqueEvents(events)).toEqual([uniqueEvent, secondEvent])
71
+ })
@@ -0,0 +1,42 @@
1
+ const os = require('os')
2
+ const { getComponentNameFromPackage } = require('./generateWrappers/utils')
3
+ const { outputFile, readFile } = require('fs-extra')
4
+
5
+ const { isVividPackageName } = require('./generateWrappers/utils')
6
+ const { dependencies, devDependencies } = require('../package.json')
7
+
8
+ const generateSupportedComponents = () => {
9
+ const allDeps = Object.entries({
10
+ ...devDependencies,
11
+ ...dependencies
12
+ })
13
+
14
+ const reducePackagesToVividComponentsList = (acc, [name, version]) => {
15
+ if (!isVividPackageName(name)) {
16
+ return acc
17
+ }
18
+ const componentName = getComponentNameFromPackage(name)
19
+ return [...acc, `| ${componentName} | ${name} | ${version} |`]
20
+ }
21
+
22
+ return allDeps.reduce(
23
+ reducePackagesToVividComponentsList,
24
+ [
25
+ '| Component Name | Package Name | Package Version |',
26
+ '|----------------|--------------|-----------------|'
27
+ ]
28
+ )
29
+ }
30
+
31
+ const updateSupportedComponents = async (readmePath) => {
32
+ const packageList = generateSupportedComponents()
33
+ const readme = await readFile(readmePath, { encoding: 'utf8' })
34
+ await outputFile(
35
+ readmePath,
36
+ // this finds a table, might be a problem if we have more than one ;)
37
+ // need the extra empty string to have a new line before the next section
38
+ readme.replace(/((\|[ -][^|\r\n]*)+\|(\r?\n|\r)?)+/gm, [...packageList, ''].join(os.EOL))
39
+ )
40
+ }
41
+
42
+ updateSupportedComponents('README.md')
@@ -0,0 +1,81 @@
1
+ const ora = require('ora')
2
+ const { EOL } = require('os')
3
+ const { spawn } = require('child_process')
4
+ const { dependencies } = require('../package.json')
5
+
6
+ const spinner = ora()
7
+
8
+ const spawnPromise = (...args) => new Promise((resolve, reject) => {
9
+ const cmd = spawn(...args)
10
+ const stdout = []
11
+ const stderr = []
12
+ cmd.stdout.on('data', (data) => stdout.push(data))
13
+ cmd.stderr.on('data', (data) => stderr.push(data))
14
+ cmd.on('close', (status) => status ? reject(stderr.join('')) : resolve(stdout.join('')))
15
+ cmd.on('error', () => reject(stderr.join('')))
16
+ })
17
+
18
+ // TODO: find a better way to load complete search results when searching NPM
19
+ // naive way to force paging when doing NPM search
20
+ // NPM limits the number of packages it returns and drops some versions and packages all together
21
+ const forcePaging = (pattern = '') =>
22
+ 'abcdefghijklmnopqrstuvwxyz'.split('').map((letter) => `${pattern}-${letter}`)
23
+
24
+ const ignoredPackages = [
25
+ '@vonage/vwc-angular-forms',
26
+ '@vonage/vwc-angular-dialog',
27
+ '@vonage/vwc-toggle-buttons-group',
28
+ '@vonage/vwc-relative-time'
29
+ ]
30
+
31
+ const defaultPatterns = [
32
+ 'vonage/vvd-context',
33
+ 'vonage/vvd-core',
34
+ 'vonage/vvd-fonts',
35
+ ...forcePaging('vonage/vwc')
36
+ ]
37
+
38
+ const removeIgnoredPackages = ({ name }) => !ignoredPackages.includes(name)
39
+
40
+ const keepOnlyChangedPackages = ({ name, version }) => dependencies[name] !== `^${version}`
41
+
42
+ const getPackages = async (patterns = defaultPatterns) => {
43
+ const packages = []
44
+ spinner.start('')
45
+ for (const pattern of patterns) {
46
+ spinner.text = `Searching for Vivid packages to update. [found: ${packages.length}]`
47
+ try {
48
+ const stdout = await spawnPromise('npm', ['search', '--json', '--no-description', pattern], { encoding: 'utf8' })
49
+ packages.push(...JSON.parse(stdout).filter(removeIgnoredPackages).filter(keepOnlyChangedPackages))
50
+ } catch {
51
+ }
52
+ }
53
+ spinner.clear()
54
+ return packages
55
+ }
56
+
57
+ const updatePackageJson = async () => {
58
+ const packages = await getPackages()
59
+ if (!packages.length) {
60
+ spinner.info('Nothing to update. All packages already in latest versions.')
61
+ return
62
+ }
63
+ let updated = 0
64
+ spinner.succeed(`Found ${packages.length} packages needing update.`)
65
+ spinner.start()
66
+ for (const { name, version } of packages) {
67
+ const versionedPackage = `${name}@^${version}`
68
+ spinner.text = `Updating '${name}@${dependencies[name]}' to '^${version}'. [updated: ${updated}/${packages.length}]`
69
+ try {
70
+ await spawnPromise('yarn', ['add', versionedPackage], { encoding: 'utf8' })
71
+ updated++
72
+ } catch (errorMessage) {
73
+ spinner.fail()
74
+ spinner.fail(errorMessage.trim(EOL))
75
+ spinner.start()
76
+ }
77
+ }
78
+ spinner.info(`Updated ${updated} of ${packages.length}`)
79
+ }
80
+
81
+ updatePackageJson()
@@ -0,0 +1,15 @@
1
+ /* global HTMLElement */
2
+ import { createRoot } from 'react-dom/client'
3
+
4
+ /**
5
+ * Renders the cell contents using React 18.x api
6
+ *
7
+ * @param {ReactNode} children - renderer contents
8
+ * @param {Container & { rootRenderer?: Root }} container - HTMLElement root container
9
+ */
10
+ export const cellRendererFactory = (children, container) => {
11
+ const root = container?.rootRenderer ?? createRoot(container)
12
+
13
+ root.render(children)
14
+ container.rootRenderer = root
15
+ }
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './initialization/initVivid'
2
+ export * from './patches'
3
+ export * from './dataGrid'
@@ -0,0 +1,24 @@
1
+ /* global HTMLElement */
2
+ import context from '@vonage/vvd-context'
3
+ import { init } from '@vonage/vvd-fonts'
4
+
5
+ /**
6
+ * mounts Vivid context (styles) & Fonts into the target scope / document
7
+ * - target scope may by any `HTMLElement` or `Document` or `DocumentFragment` (including `ShadowRoot`)
8
+ * - default target (when not specified) is the document visible in the current scope
9
+ * - the API is idempotent, the style/s will be mounted only once, even if API called multiple times
10
+ *
11
+ * @param {Document | DocumentFragment | HTMLElement} target - target document/shadow root/element to mount the CSS into
12
+ * @param {Function} callback - callback function to be invoked once init is done
13
+ * @throws {Error} error - if the provided target argument is `null` or not a Node of type `Document` / `DocumentFragment` / `HTMLElement`
14
+ */
15
+ export const initVivid = (target, callback) => {
16
+ if (target instanceof HTMLElement) {
17
+ target.classList.add('vivid-scope')
18
+ target = undefined
19
+ }
20
+ return Promise.all([
21
+ init(),
22
+ context.mount(target)
23
+ ]).then(callback)
24
+ }
@@ -0,0 +1,2 @@
1
+ export * from './vwcCardWithMenu'
2
+ export * from './vwcCardHeadingCrop'
@@ -0,0 +1,28 @@
1
+ import { vwcTooltipEllipsisDecorator } from "../vwcTooltip"
2
+
3
+ /**
4
+ * Patches provided `VwcCard` (styles) to crop long heading text and
5
+ * shows browser tooltip when actually cropped
6
+ *
7
+ * @param {HTMLElement} element - target `VwcCard` element to apply the `heading` cropping logic to
8
+ * @example <VwcCard ref={vwcCardHeadingCropDecorator(text)} heading={text} />
9
+ */
10
+ export const vwcCardHeadingCropDecorator = text => element =>
11
+ setTimeout(() => {
12
+ const cardContentElement = element?.shadowRoot.querySelector(
13
+ '.vwc-card-content'
14
+ )
15
+ const titleElement = element?.shadowRoot.querySelector(
16
+ '.vwc-card-title'
17
+ )
18
+ vwcTooltipEllipsisDecorator(text)(titleElement)
19
+ if (cardContentElement?.clientWidth < titleElement?.clientWidth) {
20
+ const computedCardContentStyle = window.getComputedStyle(cardContentElement, null)
21
+ titleElement.setAttribute('title', text)
22
+ titleElement.style.width = computedCardContentStyle.getPropertyValue('width')
23
+ titleElement.style.overflow = 'hidden'
24
+ titleElement.style.display = 'block'
25
+ titleElement.style['white-space'] = 'nowrap'
26
+ titleElement.style['text-overflow'] = 'ellipsis'
27
+ }
28
+ }, 0)
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Patches provided `VwcCard` (styles) to allow a sub menu triggered from an
3
+ * action in the card to appear over the card and not inside of it
4
+ *
5
+ * @param {HTMLElement} element - target `VwcCard` element containing the action
6
+ * that triggers the menu
7
+ * @example <VwcCard ref={vwcCardWithMenu}><VwcMenu slot='actions' /></VwcCard>
8
+ */
9
+ export const vwcCardWithMenu = (element) => setTimeout(() => {
10
+ const card = element?.shadowRoot.querySelector('.vwc-card')
11
+ if (card) {
12
+ card.style.overflow = 'unset'
13
+ }
14
+ }, 0)
@@ -0,0 +1,6 @@
1
+ export * from './vwcDataGrid'
2
+ export * from './vwcTooltip'
3
+ export * from './VwcCard'
4
+ export * from './vwcNoteContentOverflow'
5
+ export * from './vwcSnackBarHtmlMessage'
6
+ export * from './vwcSetAttributeValue'
@@ -0,0 +1,26 @@
1
+ const createVaadinGridStylePatchElement = () => {
2
+ const styleElement = document.createElement('style')
3
+ styleElement.innerHTML = `
4
+ #header {
5
+ z-index: 0;
6
+ }
7
+ [part~='cell'] ::slotted(vaadin-grid-cell-content) {
8
+ overflow: visible;
9
+ }`
10
+ return styleElement
11
+ }
12
+
13
+ /**
14
+ * Patches `VwcDataGrid` (styles) to allow cell overflow to show
15
+ * - `VwcSlider` tooltips off the cell boundaries uncropped by the grid
16
+ *
17
+ * @param {HTMLElement} gridElement - target datagrid element to mount the CSS into
18
+ * @example <VwcDataGrid ref={vwcDataGridElementCellOverflowDecorator} />
19
+ */
20
+ export const vwcDataGridElementCellOverflowDecorator = gridElement =>
21
+ setTimeout(() => {
22
+ const component = gridElement?.shadowRoot
23
+ .querySelector('vaadin-grid')?.shadowRoot
24
+
25
+ component && component.append(createVaadinGridStylePatchElement())
26
+ }, 0)
@@ -0,0 +1,20 @@
1
+ const createStyleElement = () => {
2
+ const styleElement = document.createElement('style')
3
+ styleElement.innerHTML = `
4
+ .vwc-note {
5
+ contain: inherit !important;
6
+ }`
7
+ return styleElement
8
+ }
9
+
10
+ /**
11
+ * Patches `VwcNote` (styles) to allow content overflow
12
+ *
13
+ * @param {HTMLElement} noteElement - target element to mount the CSS into
14
+ * @example <VwcNote ref={vwcNoteContentOverflowDecorator} />
15
+ */
16
+ export const vwcNoteContentOverflowDecorator = noteElement =>
17
+ setTimeout(() => {
18
+ const component = noteElement?.shadowRoot
19
+ component && component.append(createStyleElement())
20
+ }, 0)
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Patches attribute value. You can pass now a `value` to the `VwcIconButton` as
3
+ * in normal buttons
4
+ *
5
+ * @param {any} attribute
6
+ * @param {any} value
7
+ * @param {HTMLElement} element
8
+ * @returns
9
+ */
10
+ export const vwcSetAttributeValue = (attribute, value) => (element) => {
11
+ element?.setAttribute(attribute, value)
12
+ }
@@ -0,0 +1,21 @@
1
+ const createHtmlMessageElement = (html) => {
2
+ const element = document.createElement('div')
3
+ element.setAttribute('class', 'mdc-snackbar__label')
4
+ element.setAttribute('role', 'status')
5
+ element.setAttribute('aria-live', 'polite')
6
+ element.innerHTML = html
7
+ return element
8
+ }
9
+
10
+ /**
11
+ * Patches `VwcSnackbar` to allow html message text
12
+ *
13
+ * @param {HTMLElement} element - target element to patch
14
+ * @example <VwcSnackbar ref={vwcSnackBarHtmlMessageDecorator('<b>bold</b>')} />
15
+ */
16
+ export const vwcSnackBarHtmlMessageDecorator = (htmlMessage = '<b>bold</b>') => element =>
17
+ setTimeout(() => {
18
+ const component = element?.shadowRoot.querySelector('.header-and-label')
19
+ component?.style.setProperty('width', '100%')
20
+ component?.append(createHtmlMessageElement(htmlMessage))
21
+ }, 0)
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Patches provided HTMLElement (styles) to crop long text and
3
+ * shows browser tooltip when actually cropped
4
+ *
5
+ * @param {HTMLElement} element - target element to apply the text cropping logic to
6
+ * @example <span ref={vwcTooltipEllipsisDecorator(text)} >{text}</span>
7
+ */
8
+ export const vwcTooltipEllipsisDecorator = fullText => element =>
9
+ setTimeout(() => {
10
+ const isTextCropped = element?.clientHeight < element?.scrollHeight
11
+ if (isTextCropped && element) {
12
+ element.setAttribute('title', fullText)
13
+ }
14
+ }, 0)
15
+
16
+ /**
17
+ * Patches provided VwcTooltip instance to open/close tooltip on mouse hover
18
+ *
19
+ * @param {HTMLElement} tooltipElement - target element to apply behavior to
20
+ * @param {number} timeout - timeout before showing tooltip, default: 1000
21
+ * @param {string} minWidth - min width in pixels, default: 'none'
22
+ * @example <VwcTooltip ref={vwcTooltipShowOnHoverDecorator()} />
23
+ */
24
+ export const vwcTooltipShowOnHoverDecorator = (minWidth = 'none', timeout = 1000) => tooltipElement =>
25
+ setTimeout(() => {
26
+ if (!tooltipElement) {
27
+ return
28
+ }
29
+ const anchorElement = document.getElementById(tooltipElement.anchor)
30
+ if (!anchorElement) {
31
+ return
32
+ }
33
+ anchorElement.style.setProperty('pointer-events', 'auto')
34
+ tooltipElement.style.setProperty('--tooltip-inline-size', minWidth)
35
+
36
+ let showTimeoutHandler
37
+ anchorElement.addEventListener("mouseover", () => {
38
+ showTimeoutHandler = setTimeout(() => {
39
+ tooltipElement.open = true
40
+ }, timeout)
41
+ })
42
+ anchorElement.addEventListener("mouseout", () => {
43
+ clearTimeout(showTimeoutHandler)
44
+ tooltipElement.open = false
45
+ })
46
+ }, 0)
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import VwcAccordion from '../../dist/VwcAccordion'
3
+
4
+ export const Default = () => <VwcAccordion />
5
+ export default {
6
+ title: 'VwcAccordion',
7
+ argTypes: {
8
+ //
9
+ // Example values
10
+ // numberValue: { control: 'number', defaultValue: 123 },
11
+ // booleanValue: { control: 'boolean', defaultValue: true },
12
+ // objectValue: { control: 'object', defaultValue: {} },
13
+ // stringValue: { control: 'string', defaultValue: 'string' },
14
+ // colorValue: { control: 'color' },
15
+ // dateValue: { control: 'date' }
16
+ //
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import VwcActionGroup from '../../dist/VwcActionGroup'
3
+
4
+ export const Default = () => <VwcActionGroup />
5
+ export default {
6
+ title: 'VwcActionGroup',
7
+ argTypes: {
8
+ //
9
+ // Example values
10
+ // numberValue: { control: 'number', defaultValue: 123 },
11
+ // booleanValue: { control: 'boolean', defaultValue: true },
12
+ // objectValue: { control: 'object', defaultValue: {} },
13
+ // stringValue: { control: 'string', defaultValue: 'string' },
14
+ // colorValue: { control: 'color' },
15
+ // dateValue: { control: 'date' }
16
+ //
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import VwcBadge from '../../dist/VwcBadge'
3
+
4
+ export const Default = () => <VwcBadge />
5
+ export default {
6
+ title: 'VwcBadge',
7
+ argTypes: {
8
+ //
9
+ // Example values
10
+ // numberValue: { control: 'number', defaultValue: 123 },
11
+ // booleanValue: { control: 'boolean', defaultValue: true },
12
+ // objectValue: { control: 'object', defaultValue: {} },
13
+ // stringValue: { control: 'string', defaultValue: 'string' },
14
+ // colorValue: { control: 'color' },
15
+ // dateValue: { control: 'date' }
16
+ //
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import VwcBanner from '../../dist/VwcBanner'
3
+
4
+ export const Default = () => <VwcBanner />
5
+ export default {
6
+ title: 'VwcBanner',
7
+ argTypes: {
8
+ //
9
+ // Example values
10
+ // numberValue: { control: 'number', defaultValue: 123 },
11
+ // booleanValue: { control: 'boolean', defaultValue: true },
12
+ // objectValue: { control: 'object', defaultValue: {} },
13
+ // stringValue: { control: 'string', defaultValue: 'string' },
14
+ // colorValue: { control: 'color' },
15
+ // dateValue: { control: 'date' }
16
+ //
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import VwcButton from '../../dist/VwcButton'
3
+
4
+ export const Default = () => <VwcButton />
5
+ export default {
6
+ title: 'VwcButton',
7
+ argTypes: {
8
+ //
9
+ // Example values
10
+ // numberValue: { control: 'number', defaultValue: 123 },
11
+ // booleanValue: { control: 'boolean', defaultValue: true },
12
+ // objectValue: { control: 'object', defaultValue: {} },
13
+ // stringValue: { control: 'string', defaultValue: 'string' },
14
+ // colorValue: { control: 'color' },
15
+ // dateValue: { control: 'date' }
16
+ //
17
+ }
18
+ }
@@ -0,0 +1,47 @@
1
+ import React from 'react'
2
+ import VwcButtonToggleGroup from '../../dist/VwcButtonToggleGroup'
3
+ import VwcButton from '../../dist/VwcButton'
4
+
5
+ export const Default = () => {
6
+ return (
7
+ <VwcButtonToggleGroup required values={['foo']}>
8
+ <VwcButton value='foo'>Foo</VwcButton>
9
+ <VwcButton value='bar'>Bar</VwcButton>
10
+ </VwcButtonToggleGroup>
11
+ )
12
+ }
13
+
14
+ export const RealtimeValuesSet = () => {
15
+ return (
16
+ <VwcButtonToggleGroup
17
+ values={[]}
18
+ ref={btnGroupElement =>
19
+ setTimeout(() => {
20
+ if (!btnGroupElement) {
21
+ return
22
+ }
23
+ btnGroupElement.values = ['bar']
24
+ }, 0)
25
+ }
26
+ required
27
+ >
28
+ <VwcButton value='foo'>Foo</VwcButton>
29
+ <VwcButton value='bar'>Bar</VwcButton>
30
+ </VwcButtonToggleGroup>
31
+ )
32
+ }
33
+
34
+ export default {
35
+ title: 'VwcButtonToggleGroup',
36
+ argTypes: {
37
+ //
38
+ // Example values
39
+ // numberValue: { control: 'number', defaultValue: 123 },
40
+ // booleanValue: { control: 'boolean', defaultValue: true },
41
+ // objectValue: { control: 'object', defaultValue: {} },
42
+ // stringValue: { control: 'string', defaultValue: 'string' },
43
+ // colorValue: { control: 'color' },
44
+ // dateValue: { control: 'date' }
45
+ //
46
+ }
47
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import VwcCalendar from '../../dist/VwcCalendar'
3
+
4
+ export const Default = () => <VwcCalendar />
5
+ export default {
6
+ title: 'VwcCalendar',
7
+ argTypes: {
8
+ //
9
+ // Example values
10
+ // numberValue: { control: 'number', defaultValue: 123 },
11
+ // booleanValue: { control: 'boolean', defaultValue: true },
12
+ // objectValue: { control: 'object', defaultValue: {} },
13
+ // stringValue: { control: 'string', defaultValue: 'string' },
14
+ // colorValue: { control: 'color' },
15
+ // dateValue: { control: 'date' }
16
+ //
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import VwcCalendarEvent from '../../dist/VwcCalendarEvent'
3
+
4
+ export const Default = () => <VwcCalendarEvent />
5
+ export default {
6
+ title: 'VwcCalendarEvent',
7
+ argTypes: {
8
+ //
9
+ // Example values
10
+ // numberValue: { control: 'number', defaultValue: 123 },
11
+ // booleanValue: { control: 'boolean', defaultValue: true },
12
+ // objectValue: { control: 'object', defaultValue: {} },
13
+ // stringValue: { control: 'string', defaultValue: 'string' },
14
+ // colorValue: { control: 'color' },
15
+ // dateValue: { control: 'date' }
16
+ //
17
+ }
18
+ }