@webority/ui-react 0.51.1 → 0.51.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./warnInvalidValue.js";import t from"./warnUnknownProps.js";import
|
|
1
|
+
import e from"./warnInvalidValue.js";import t from"./warnUnknownProps.js";import ee from"./AppInfoTip.js";import n from"./AppRequiredMark.js";import r,{optionsEqual as i}from"./useWuiControl.js";import a from"./useNodeLabels.js";import{forwardRef as o,useEffect as s,useId as c,useRef as l}from"react";import{Fragment as u,jsx as d,jsxs as f}from"react/jsx-runtime";import"@webority/ui-elements/elements/select";var p=[`sm`,`lg`],m=(e,t)=>({value:e.value,label:t,icon:e.icon}),h=o(function({value:o,onChange:h,options:g=[],placeholder:_=`Select...`,searchPlaceholder:v=`Search...`,searchable:y=!1,clearable:b=!1,size:x,icon:S,prefix:C,suffix:w,floatingLabel:T=!1,disabled:E,label:D,required:O=!1,error:k,hint:A,help:j,helpLabel:M=`More information`,id:N,name:P,className:F=``,fieldClassName:I=``,"aria-label":L,"aria-labelledby":R,"aria-describedby":z,...B},V){t(`AppSelect`,B),e(`AppSelect`,`size`,x,p);let H=c(),{setRef:U,innerRef:W}=r({ref:V,value:o??``,onChange:h}),{portal:G,toElementOptions:K}=a(g),q=l({el:null,options:null});s(()=>{let e=W.current;if(!e||q.current.el===e&&q.current.options===g)return;q.current={el:e,options:g};let t=K(g,m);i(t,e.options)||(e.options=t)});let J=N||H,Y=T&&D,X=k&&J?`${J}-error`:void 0,Z=A&&J?`${J}-hint`:void 0,Q=f(u,{children:[d(`wui-select`,{"aria-label":L||(typeof D==`string`?D:void 0),"aria-labelledby":R||void 0,"aria-describedby":X||Z||z||void 0,"aria-invalid":k?`true`:void 0,ref:U,id:J,name:P,placeholder:T&&D?` `:_,"search-placeholder":v,searchable:y?``:void 0,clearable:b?``:void 0,size:x||void 0,icon:S||void 0,disabled:E?``:void 0,required:O?``:void 0,className:F||void 0,...B}),G]}),$=!Y&&(C!=null||w!=null)?f(`div`,{className:`input-affixed`,children:[C!=null&&d(`span`,{className:`affix affix-pre`,children:C}),Q,w!=null&&d(`span`,{className:`affix affix-suf`,children:w})]}):Q;return!D&&!k&&!A?$:f(`div`,{className:[`field`,I].filter(Boolean).join(` `),children:[D&&!Y&&f(`label`,{className:`label`,htmlFor:J,children:[D,O&&d(n,{}),j&&d(ee,{label:M,children:j})]}),Y?f(`div`,{className:`field-float`,children:[Q,f(`label`,{className:`float-label`,htmlFor:J,children:[D,O&&d(n,{})]})]}):$,k?d(`div`,{className:`field-error`,id:X,children:k}):A?d(`div`,{className:`field-hint`,id:Z,children:A}):null]})});export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./warnInvalidValue.js";import t from"./warnUnknownProps.js";import n,{optionsEqual as r}from"./useWuiControl.js";import{useEffect as
|
|
1
|
+
import e from"./warnInvalidValue.js";import t from"./warnUnknownProps.js";import n,{optionsEqual as r}from"./useWuiControl.js";import i from"./useNodeLabels.js";import{useEffect as a}from"react";import{Fragment as o,jsx as s,jsxs as c}from"react/jsx-runtime";import"@webority/ui-elements/elements/select";var l=[`sm`,`lg`],u=(e,t)=>({value:e.value,label:t,icon:e.icon});function d({value:d,onChange:f,options:p=[],placeholder:m=`Select...`,name:h,ariaLabel:g,id:_,disabled:v,size:y,icon:b,prefix:x,className:S,...C}){t(`AppSelectMini`,C),e(`AppSelectMini`,`size`,y,l);let{setRef:w,innerRef:T}=n({value:d??``,onChange:f}),{portal:E,toElementOptions:D}=i(p);return a(()=>{let e=T.current;if(!e)return;let t=D(p,u);r(t,e.options)||(e.options=t)},[p,T,D]),a(()=>{let e=T.current;if(e)for(let[t,n]of[[`icon`,b],[`prefix`,x]])n==null||n===``?e.removeAttribute(t):e.setAttribute(t,n)},[b,x,T]),c(o,{children:[s(`wui-select`,{ref:w,name:h,compact:``,id:_,placeholder:m,"aria-label":g,size:y||void 0,disabled:v?``:void 0,className:S,...C}),E]})}export{d as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{withTrustedLabel as e}from"@webority/ui-elements/helpers";import{createElement as t,useCallback as n,useRef as r}from"react";import{createPortal as i}from"react-dom";var a=e=>e?.label!=null&&typeof e.label==`object`;function o(o){let s=r(null),c=o.filter(a);c.length&&s.current===null&&(s.current=document.createElement(`div`));let l=n((t,n)=>{let r=0;return t.map(t=>{if(!a(t))return n(t,t?.label??t?.text??``);let i=s.current.children[r].innerHTML;return r+=1,e(n(t,i))})},[]);return{portal:c.length?i(c.map(e=>t(`span`,{key:String(e.value)},e.label)),s.current):null,toElementOptions:l}}export{o as default};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import "@webority/ui-elements/elements/select";
|
|
2
2
|
/**
|
|
3
3
|
* @param {object} props
|
|
4
|
+
* @param {Array<{ value: string, label?: import('react').ReactNode, text?: string, icon?: string }>} [props.options]
|
|
5
|
+
* The choices. A label may be a node (`<>LPZ 0<sub>B</sub></>`): it renders as static markup in
|
|
6
|
+
* the list and the value, and search and the option's accessible name use its text.
|
|
4
7
|
* @param {string} [props.className] Class to apply to the control element.
|
|
5
8
|
* @param {string} [props.fieldClassName] Class to apply to the wrapper field div.
|
|
6
9
|
* @param {import('react').ReactNode} [props.prefix] A bordered box before the select (e.g. "+91", "Tag"),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lets a select option carry a React node as its label (a subscript, a bold run, a badge).
|
|
3
|
+
*
|
|
4
|
+
* The shared select element renders its options from strings, so each node label is rendered
|
|
5
|
+
* by React into a detached host through a portal, and the markup React produced is handed to
|
|
6
|
+
* the element marked as trusted: React escaped every text and attribute in it, so it is author
|
|
7
|
+
* markup, the same as a Razor option's child content. The element shows that markup in the list
|
|
8
|
+
* and as the selected value, and filters, typeahead-matches and names each option by its text,
|
|
9
|
+
* so `LPZ 0<sub>B</sub>` is found by typing "0b" and read out as "LPZ 0B".
|
|
10
|
+
*
|
|
11
|
+
* The markup is static: handlers and state inside a label do not run in the menu, and it is
|
|
12
|
+
* read again only when the `options` array changes.
|
|
13
|
+
*
|
|
14
|
+
* @param {Array<{ value: string, label?: import('react').ReactNode }>} options
|
|
15
|
+
* @returns {{
|
|
16
|
+
* portal: import('react').ReactPortal | null,
|
|
17
|
+
* toElementOptions: (options: object[], shape: (o: object, label: string) => object) => object[],
|
|
18
|
+
* }} `portal` goes anywhere in the wrapper's tree (it adds no DOM there). `toElementOptions` is
|
|
19
|
+
* called from an effect, after the portal has committed, with the same `options`; it maps each
|
|
20
|
+
* option through `shape` with its text label or its markup.
|
|
21
|
+
*/
|
|
22
|
+
export default function useNodeLabels(options: Array<{
|
|
23
|
+
value: string;
|
|
24
|
+
label?: import('react').ReactNode;
|
|
25
|
+
}>): {
|
|
26
|
+
portal: import('react').ReactPortal | null;
|
|
27
|
+
toElementOptions: (options: object[], shape: (o: object, label: string) => object) => object[];
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/ui-react",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.3",
|
|
4
4
|
"description": "Webority shared React component library — App* primitives on react-bootstrap + the @webority/theme design system.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@webority/theme": "0.51.
|
|
31
|
-
"@webority/ui-elements": "0.51.
|
|
30
|
+
"@webority/theme": "0.51.3",
|
|
31
|
+
"@webority/ui-elements": "0.51.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@webority/analytics": "^0.
|
|
34
|
+
"@webority/analytics": "^0.21.0",
|
|
35
35
|
"bootstrap": "5.3.3",
|
|
36
36
|
"react": "^19.0.0",
|
|
37
37
|
"react-bootstrap": "^2.10.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@types/react": "^19.2.17",
|
|
46
46
|
"@vitejs/plugin-react": "^6.0.1",
|
|
47
47
|
"@vitest/coverage-v8": "5.0.1",
|
|
48
|
-
"@webority/analytics": "0.
|
|
48
|
+
"@webority/analytics": "0.21.0",
|
|
49
49
|
"bootstrap": "5.3.3",
|
|
50
50
|
"jsdom": "30.1.1",
|
|
51
51
|
"react": "^19.2.6",
|