march-ui 0.0.3 → 0.0.5

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.
package/Button/index.jsx CHANGED
@@ -8,6 +8,7 @@ const Button = () => {
8
8
  const {
9
9
  icon, title, state,
10
10
  wide, volume, view,
11
+ formRef,
11
12
  ...attributes
12
13
  } = attrs
13
14
  const classes = classNames('button', {
package/Form/index.jsx CHANGED
@@ -11,13 +11,30 @@ const defaultAttributes = {
11
11
  }
12
12
 
13
13
  const Form = ({ attrs }) => {
14
- let { submit, beforeSubmit, afterSubmit, onerror, reportValidity } = { ...defaultAttributes, ...attrs }
14
+ let { submit, beforeSubmit, afterSubmit, onerror/*, reportValidity*/ } = { ...defaultAttributes, ...attrs }
15
15
  let isPending
16
+ const eventListeners = new Map()
17
+ const dispatch = (eventName) => {
18
+ const listeners = eventListeners.get(eventName)
19
+ if (listeners)
20
+ for (let listener of listeners.values())
21
+ listener()
22
+ }
23
+ const formRef = {
24
+ subscribe: (eventName, listener) => {
25
+ if (!eventListeners.has(eventName))
26
+ eventListeners.set(eventName, new Set())
27
+ const listeners = eventListeners.get(eventName)
28
+ listeners.add(listener)
29
+ return () => listeners.delete(listener)
30
+ }
31
+ }
16
32
  let onsubmit = evt => {
17
33
  const formElement = evt.target
18
34
  if (!formElement.checkValidity()) {
19
35
  formElement.reportValidity()
20
36
  } else {
37
+ dispatch('formValid')
21
38
  isPending = false
22
39
  beforeSubmit(evt)
23
40
  Promise
@@ -33,7 +50,13 @@ const Form = ({ attrs }) => {
33
50
  }
34
51
  return {
35
52
  view({ attrs, children }) {
36
- const { icon, title, onsubmit: onsubmitNext, ...attributes } = {
53
+ const {
54
+ icon,
55
+ title,
56
+ onsubmit: onsubmitNext,
57
+ submit, beforeSubmit, afterSubmit, onerror, // internal usage only
58
+ ...attributes
59
+ } = {
37
60
  method: 'POST',
38
61
  enctype: 'multipart/form-data',
39
62
  ...attrs
@@ -49,7 +72,11 @@ const Form = ({ attrs }) => {
49
72
  <div class="form__title">{title}</div>
50
73
  </div>
51
74
  <div class="form__body">
52
- {children}
75
+ {children.map(vnode => {
76
+ if (vnode && vnode.attrs)
77
+ vnode.attrs.formRef = formRef
78
+ return vnode
79
+ })}
53
80
  </div>
54
81
  </form>
55
82
  )
package/Tab/index.jsx CHANGED
@@ -1,10 +1,15 @@
1
- const Tab = () => {
1
+ const Tab = ({ attrs }) => {
2
2
  return {
3
- view({ children }) {
3
+ view({ attrs, children }) {
4
+ const { key, title, ...attributes } = attrs
4
5
  return (
5
- <div class="tab">
6
- {children}
7
- </div>
6
+ <>
7
+ {children.map(vnode => {
8
+ if (vnode && vnode.attrs)
9
+ vnode.attrs = { ...vnode.attrs, ...attributes }
10
+ return vnode
11
+ })}
12
+ </>
8
13
  )
9
14
  }
10
15
  }
package/Tabs/index.css CHANGED
@@ -1,6 +1,11 @@
1
+ .tabs {
2
+ width: max-content;
3
+ }
4
+
1
5
  .tabs__list {
6
+ box-sizing: border-box;
2
7
  display: flex;
3
- width: max-content;
8
+ width: 100%;
4
9
  flex-direction: row;
5
10
  justify-content: center;
6
11
  padding: 0.25em;
@@ -9,8 +14,9 @@
9
14
  }
10
15
 
11
16
  .tabs__switch {
17
+ box-sizing: border-box;
12
18
  display: flex;
13
- width: max-content;
19
+ width: 100%;
14
20
  flex-direction: row;
15
21
  justify-content: center;
16
22
  border-radius: 0.4em;
@@ -19,11 +25,14 @@
19
25
  }
20
26
 
21
27
  .tab__title {
28
+ box-sizing: border-box;
22
29
  display: flex;
23
- flex-grow: 0;
30
+ flex-grow: 1;
24
31
  flex-shrink: 0;
25
32
  padding: 0.25em 1em;
26
33
  cursor: pointer;
34
+ justify-content: center;
35
+ align-items: center;
27
36
  }
28
37
 
29
38
  .tab__title.tab__title--active {
package/Tabs/index.jsx CHANGED
@@ -1,17 +1,27 @@
1
1
  import './index.css'
2
2
  import './colors.css'
3
3
  import classNames from 'classnames'
4
+ import Tab from '../Tab'
4
5
 
5
6
  const Tabs = ({ attrs }) => {
6
7
  let { active } = attrs
8
+ const switchTab = (key, onchange) => () => {
9
+ active = key
10
+ if (onchange)
11
+ onchange()
12
+ }
7
13
  return {
8
- view({ children }) {
9
- const tabs = children.filter(({ tag: { name } }) => name === 'Tab')
10
- .map(tab => {
11
- const { key, attrs: { title }, children: content } = tab
12
- return { key, title, content }
14
+ view({ attrs: { active: activeNext, onchange, ...attributes }, children }) {
15
+ const tabs = children.filter(({ tag }) => tag === Tab)
16
+ .map((tab, i) => {
17
+ const { key, attrs: { title } } = tab
18
+ tab.attrs = { ...tab.attrs, ...attributes }
19
+ return { key: key === undefined ? i : key, title, tab }
13
20
  })
14
21
  const activeIndex = tabs.findIndex(({ key }) => key === active || active === undefined)
22
+ if (activeIndex >= 0) {
23
+ active = tabs[activeIndex].key
24
+ }
15
25
  const classes = 'tabs'
16
26
  return (
17
27
  <div class={classes}>
@@ -20,12 +30,12 @@ const Tabs = ({ attrs }) => {
20
30
  {tabs.map(({ key, title }, i) => {
21
31
  return <div class={classNames('tab__title', {
22
32
  'tab__title--active': i === activeIndex
23
- })} onclick={() => { active = key }}>{title}</div>
33
+ })} onclick={switchTab(key, onchange)}>{title}</div>
24
34
  })}
25
35
  </div>
26
36
  </div>
27
37
  {activeIndex >= 0 &&
28
- <div class="tabs__content">{tabs[activeIndex].content}</div>}
38
+ <div class="tabs__content">{tabs[activeIndex].tab}</div>}
29
39
  </div>
30
40
  )
31
41
  }
@@ -101,7 +101,15 @@ const TextField = ({ attrs }) => {
101
101
  validateInput(evt.target)
102
102
  return result
103
103
  }
104
+ const subscriptions = {}
105
+ const onFormValid = () => {
106
+ state = 'valid'
107
+ }
104
108
  return {
109
+ onremove() {
110
+ Object.values(subscriptions)
111
+ .forEach(unsubscribe => unsubscribe())
112
+ },
105
113
  onupdate({ dom }) {
106
114
  const inputElement = dom.querySelector('input')
107
115
  if (state === 'valid') {
@@ -119,6 +127,7 @@ const TextField = ({ attrs }) => {
119
127
  validate: validateNext, pattern,
120
128
  placeholder: placeholderDropped,
121
129
  state: stateNext,
130
+ formRef,
122
131
  ...rest
123
132
  } = {
124
133
  ...defaultAttributes,
@@ -151,6 +160,9 @@ const TextField = ({ attrs }) => {
151
160
  ...(disabled ? { disabled } : {}),
152
161
  ...rest
153
162
  }
163
+ if (formRef) {
164
+ subscriptions.formValid = formRef.subscribe('formValid', onFormValid)
165
+ }
154
166
  return (
155
167
  <label class={classes}>
156
168
  {title && <div class="textfield__title">{title}</div>}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "march-ui",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Lightweight UI-kit for Mithril.js",
5
5
  "type": "module",
6
6
  "main": "index.js",