Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 64ec694

Browse files
committed
chore: add changeset
1 parent ca9cb8a commit 64ec694

File tree

3 files changed

+367
-8
lines changed

3 files changed

+367
-8
lines changed

.changeset/dry-mayflies-deny.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
'@chakra-ui/c-accordion': minor
3+
'@chakra-ui/c-alert': minor
4+
'@chakra-ui/c-breadcrumb': minor
5+
'@chakra-ui/c-button': minor
6+
'@chakra-ui/c-close-button': minor
7+
'@chakra-ui/c-code': minor
8+
'@chakra-ui/c-color-mode': minor
9+
'@chakra-ui/c-flex': minor
10+
'@chakra-ui/c-focus-lock': minor
11+
'@chakra-ui/c-form-control': minor
12+
'@chakra-ui/c-icon': minor
13+
'@chakra-ui/c-modal': minor
14+
'@chakra-ui/c-motion': minor
15+
'@chakra-ui/c-popper': minor
16+
'@chakra-ui/c-portal': minor
17+
'@chakra-ui/c-reset': minor
18+
'@chakra-ui/c-scroll-lock': minor
19+
'@chakra-ui/c-spinner': minor
20+
'@chakra-ui/c-theme-provider': minor
21+
'@chakra-ui/c-visually-hidden': minor
22+
'@chakra-ui/vue-next': minor
23+
'@chakra-ui/vue-layout': minor
24+
'@chakra-ui/nuxt-next': minor
25+
'@chakra-ui/vue-system': minor
26+
'@chakra-ui/vue-test-utils': minor
27+
'@chakra-ui/vue-theme': minor
28+
'@chakra-ui/vue-theme-tools': minor
29+
'@chakra-ui/vue-utils': minor
30+
'@chakra-ui/vue-a11y': minor
31+
'@chakra-ui/vue-composables': minor
32+
'@chakra-ui/vue-auto-import': minor
33+
'@chakra-ui/vue-docs': minor
34+
---
35+
36+
Create `CFormControl` component

packages/c-icon/src/index.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
1-
export * from './icon'
1+
import { defineComponent, inject, computed, h } from 'vue';
2+
import { chakra } from '@chakra-ui/vue-system';
3+
4+
function _extends() {
5+
_extends = Object.assign || function (target) {
6+
for (var i = 1; i < arguments.length; i++) {
7+
var source = arguments[i];
8+
9+
for (var key in source) {
10+
if (Object.prototype.hasOwnProperty.call(source, key)) {
11+
target[key] = source[key];
12+
}
13+
}
14+
}
15+
16+
return target;
17+
};
18+
19+
return _extends.apply(this, arguments);
20+
}
21+
22+
var fallbackIcon = {
23+
path: "\n <g stroke=\"currentColor\" strokeWidth=\"1.5\">\n <path\n strokeLinecap=\"round\"\n fill=\"none\"\n d=\"M9,9a3,3,0,1,1,4,2.829,1.5,1.5,0,0,0-1,1.415V14.25\"\n />\n <path\n fill=\"currentColor\"\n strokeLinecap=\"round\"\n d=\"M12,17.25a.375.375,0,1,0,.375.375A.375.375,0,0,0,12,17.25h0\"\n />\n <circle fill=\"none\" strokeMiterlimit=\"10\" cx=\"12\" cy=\"12\" r=\"11.25\" />\n </g>\n ",
24+
viewBox: '0 0 24 24'
25+
};
26+
var CIcon = defineComponent({
27+
props: {
28+
as: {
29+
type: [Object, String],
30+
"default": 'svg'
31+
},
32+
name: {
33+
type: [String]
34+
},
35+
size: {
36+
type: [String],
37+
"default": '1em'
38+
}
39+
},
40+
setup: function setup(props, _ref) {
41+
var slots = _ref.slots,
42+
attrs = _ref.attrs;
43+
var icons = inject('$chakraIcons');
44+
var icon = computed(function () {
45+
return (icons == null ? void 0 : icons[props == null ? void 0 : props.name]) || fallbackIcon;
46+
});
47+
var vnodeProps = computed(function () {
48+
return {
49+
w: props.size,
50+
h: props.size,
51+
display: 'inline-block',
52+
lineHeight: '1em',
53+
flexShrink: 0,
54+
color: 'currentColor',
55+
innerHTML: icon.value.path,
56+
focusable: false,
57+
viewBox: icon.value.viewBox || fallbackIcon.viewBox
58+
};
59+
});
60+
return function () {
61+
return h(chakra(props.as, {
62+
label: 'icon'
63+
}), _extends({}, icon.value.attrs || {}, vnodeProps.value, attrs), slots);
64+
};
65+
}
66+
});
67+
68+
export { CIcon };

packages/utils/src/index.ts

Lines changed: 263 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,263 @@
1-
export * from './vue-utils'
2-
export * from './layout'
3-
export * from './dom'
4-
export * from './dom-query'
5-
export * from './types'
6-
export * from './timers'
7-
export * from './props'
1+
import { isObject } from '@chakra-ui/utils';
2+
import { isVNode, provide, inject, ref, onBeforeUpdate, unref, customRef } from 'vue';
3+
4+
/**
5+
* Creates a named context, provider, and hook.
6+
*
7+
* @param options create context options
8+
*/
9+
function createContext(options) {
10+
if (options === void 0) {
11+
options = {};
12+
}
13+
14+
var _options = options,
15+
_options$strict = _options.strict,
16+
strict = _options$strict === void 0 ? true : _options$strict,
17+
_options$errorMessage = _options.errorMessage,
18+
errorMessage = _options$errorMessage === void 0 ? 'useContext: `context` is undefined. Seems you forgot to wrap component within the Provider' : _options$errorMessage,
19+
name = _options.name;
20+
var contextSymbol = Symbol(name + "Symbol");
21+
22+
function Provider(payload) {
23+
provide(contextSymbol, payload);
24+
}
25+
26+
function useContext() {
27+
var context = inject(contextSymbol, null);
28+
29+
if (!context && strict) {
30+
throw new Error(errorMessage);
31+
}
32+
33+
return context;
34+
}
35+
36+
return [Provider, useContext];
37+
}
38+
/**
39+
* Gets only the valid children of a component,
40+
* and ignores any nullish or falsy child.
41+
*
42+
* @param slots vue slots
43+
*
44+
* see https://github.com/vuejs/vue-next/blob/HEAD/packages/runtime-core/src/helpers/renderSlot.ts
45+
*/
46+
47+
function getValidChildren(slots) {
48+
var slotArray = (slots == null ? void 0 : slots["default"] == null ? void 0 : slots["default"]()) || [];
49+
return slotArray.filter(function (child) {
50+
return isVNode(child);
51+
});
52+
}
53+
54+
/** Checkes whether a provided object is a component */
55+
function isObjectComponent(subject) {
56+
var validComponentTypes = ['function', 'object'];
57+
if (!validComponentTypes.includes(typeof subject)) return false; // Is sub
58+
59+
if (isObject(subject)) {
60+
// Is object component with render function
61+
if (typeof (subject == null ? void 0 : subject.render) === 'function' && isVNode(subject.render())) return true; // Is object component with setup function
62+
else if (typeof (subject == null ? void 0 : subject.setup) === 'function') return true;
63+
}
64+
65+
return false;
66+
}
67+
68+
function orient(options) {
69+
var orientation = options.orientation,
70+
vertical = options.vertical,
71+
horizontal = options.horizontal;
72+
if (!orientation) return {};
73+
return orientation === 'vertical' ? vertical : horizontal;
74+
}
75+
76+
/** Debounce function */
77+
function debounce(func, wait, immediate) {
78+
var timeout;
79+
return function () {
80+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
81+
args[_key] = arguments[_key];
82+
}
83+
84+
if (immediate && !timeout) func.apply(void 0, args);
85+
clearTimeout(timeout);
86+
timeout = setTimeout(function () {
87+
func.apply(void 0, args);
88+
}, wait);
89+
};
90+
}
91+
92+
/**
93+
* For internal use
94+
*
95+
* Creates refs that will be bound to the template/render function.
96+
*
97+
* Why not just use the regular `ref(null)` and bind it to the element?
98+
*
99+
* 1. To avoid unwrapping template refs which maybe components. This hook will always
100+
* give us the actual element being bound the the element, and not the component
101+
* options.
102+
*
103+
* 2. In some cases where we need an up-to-date value of the ref node,
104+
* from the consuming component, we can use this hook.
105+
*
106+
* @returns []
107+
*/
108+
function useRef() {
109+
var refEl = ref(null);
110+
onBeforeUpdate(function () {
111+
// clear refs before DOM updates
112+
refEl.value = null;
113+
});
114+
/**
115+
* Getter function to bind ref to value
116+
* @param el Template ref value provided by Vue
117+
*/
118+
119+
var _ref = function _ref(el) {
120+
var _$el;
121+
122+
refEl.value = (_$el = el == null ? void 0 : el.$el) != null ? _$el : el;
123+
};
124+
125+
return [_ref, refEl];
126+
}
127+
/** Vue Component HTML Element Instance */
128+
129+
/**
130+
* Unwraps element from ref
131+
* @param elementRef Ref of template node
132+
*/
133+
function unrefElement(elementRef) {
134+
var _$el2;
135+
136+
var node = unref(elementRef);
137+
return (_$el2 = node == null ? void 0 : node.$el) != null ? _$el2 : node;
138+
}
139+
/**
140+
* Creates a ref whose value updates are debounced
141+
*
142+
* @example Simple example
143+
*
144+
* ```ts
145+
* const foo = useDebouncedRef('bar')
146+
* foo.value = 'baz'
147+
*
148+
* // foo.value to be updated to 'baz' after the delay of 300ms
149+
* ```
150+
*
151+
* @example Custom delay
152+
*
153+
* ```ts
154+
* const foo = useDebouncedRef('bar', 500)
155+
* foo.value = 'baz'
156+
*
157+
* // foo.value to be updated to 'baz' after the delay of 500ms
158+
* ```
159+
*/
160+
161+
function useDebouncedRef(initialValue, delay, immediate) {
162+
if (delay === void 0) {
163+
delay = 300;
164+
}
165+
166+
if (immediate === void 0) {
167+
immediate = false;
168+
}
169+
170+
var state = ref(initialValue);
171+
var debouncedRef = customRef(function (track, trigger) {
172+
return {
173+
get: function get() {
174+
track();
175+
return state.value;
176+
},
177+
set: debounce(function (value) {
178+
state.value = value;
179+
trigger();
180+
}, delay, immediate)
181+
};
182+
});
183+
return debouncedRef;
184+
}
185+
186+
/**
187+
* Computes the selector of an element from the DOM
188+
*
189+
* The motivation for this method is to use it in the
190+
* resolve the issue where DOM nodes seem to be
191+
* removed from the DOM during patching for reactivity.
192+
*
193+
* This was breaking the behaviour of the `useFocusLock`
194+
* hook.
195+
*
196+
* Adopted from stack overflow:
197+
* https://stackoverflow.com/questions/22515835/javascript-find-selector-of-an-element
198+
*/
199+
function getSelector(node) {
200+
var id = node.getAttribute('id');
201+
if (id) return '#' + id;
202+
var path = '';
203+
204+
var _loop = function _loop() {
205+
var name = node.localName;
206+
var parent = node.parentNode;
207+
208+
if (!parent) {
209+
path = name + ' > ' + path;
210+
return "continue";
211+
}
212+
213+
if (node.getAttribute('id')) {
214+
path = '#' + node.getAttribute('id') + ' > ' + path;
215+
return "break";
216+
}
217+
218+
var sameTagSiblings = [];
219+
var children = parent.childNodes;
220+
children = Array.prototype.slice.call(children);
221+
children.forEach(function (child) {
222+
// @ts-ignore
223+
if (child.localName == name) {
224+
sameTagSiblings.push(child);
225+
}
226+
}); // if there are more than one
227+
// children of that type use nth-of-type
228+
229+
if (sameTagSiblings.length > 1) {
230+
var index = sameTagSiblings.indexOf(node);
231+
name += ':nth-of-type(' + (index + 1) + ')';
232+
}
233+
234+
if (path) {
235+
path = name + ' > ' + path;
236+
} else {
237+
path = name;
238+
}
239+
240+
node = parent;
241+
};
242+
243+
while (node) {
244+
var _ret = _loop();
245+
246+
if (_ret === "continue") continue;
247+
if (_ret === "break") break;
248+
}
249+
250+
return path;
251+
}
252+
253+
var vueThemingProps = {
254+
colorScheme: String,
255+
variant: String,
256+
size: String,
257+
styleConfig: String
258+
};
259+
var SNA = [Number, String, Array];
260+
var SAO = [String, Array, Object];
261+
var SNAO = [Number, String, Array, Object];
262+
263+
export { SAO, SNA, SNAO, createContext, debounce, getSelector, getValidChildren, isObjectComponent, orient, unrefElement, useDebouncedRef, useRef, vueThemingProps };

0 commit comments

Comments
 (0)