@progress/kendo-react-data-tools
Version:
Includes React Pager & React Filter component, an intuitive interface to create complex filter descriptions. KendoReact Data Tools package
10 lines (9 loc) • 3.92 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
"use client";
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),p=require("prop-types"),g=require("@progress/kendo-react-buttons"),m=require("@progress/kendo-react-dropdowns"),v=require("@progress/kendo-react-intl"),x=require("@progress/kendo-svg-icons"),d=require("./operators.js"),n=require("../messages/index.js");function E(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const e=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,e.get?e:{enumerable:!0,get:()=>s[r]})}}return t.default=s,Object.freeze(t)}const l=E(b),h=s=>{s.value===void 0&&!d.unaryOperator(s.operator)&&(s.value=d.stringOperator(s.operator)?"":null)},f=class f extends l.Component{constructor(){super(...arguments),this.onFieldChange=t=>{const r=t.value.name,e=this.props.fields.find(a=>a.name===r),o=this.props.filter,i=e&&!e.operators.some(a=>a.operator===o.operator)?e.operators[0].operator:o.operator,c={field:r,operator:i};h(c),this.triggerOnFilterChange(o,c,t)},this.onOperatorChange=t=>{const r=t.value.operator,e=this.props.filter;let o;if(d.unaryOperator(r)){const{value:i,...c}=e;o={...c,operator:r}}else o={...e,operator:r};h(o),this.triggerOnFilterChange(e,o,t)},this.onInputChange=t=>{const r=this.props.filter;let e=t.nextFilter;if(d.unaryOperator(e.operator)){const o=this.props.fields.find(i=>i.name===e.field);e={...e,operator:o&&o.operators[0].operator||e.operator}}this.triggerOnFilterChange(r,e,t)},this.triggerOnFilterChange=(t,r,e)=>{const o={prevFilter:t,nextFilter:r,syntheticEvent:e.syntheticEvent,nativeEvent:e.nativeEvent,target:this};this.props.onChange.call(void 0,o)},this.onFilterRemove=t=>{const r={filter:this.props.filter,syntheticEvent:t.syntheticEvent,nativeEvent:t.nativeEvent,target:this};this.props.onRemove.call(void 0,r)}}render(){const t=v.provideLocalizationService(this),{fields:r,filter:e,ariaLabel:o=t.toLanguageString(n.filterExpressionAriaLabel,n.messages[n.filterExpressionAriaLabel])}=this.props,i=r.find(a=>a.name===e.field),c=(i&&i.operators||[]).map(a=>({...a,text:t.toLanguageString(a.text,n.messages[a.text]||a.text)}));return l.createElement("div",{className:"k-filter-toolbar"},l.createElement(g.Toolbar,{keyboardNavigation:!1,role:"toolbar",ariaLabel:o},l.createElement(g.ToolbarItem,{className:"k-filter-field"},l.createElement(m.DropDownList,{tabIndex:-1,data:r,textField:"label",value:r.find(a=>a.name===e.field),onChange:this.onFieldChange,ariaLabel:t.toLanguageString(n.filterExpressionDropdownAriaLabel,n.messages[n.filterExpressionDropdownAriaLabel])})),l.createElement(g.ToolbarItem,{className:"k-filter-operator"},l.createElement(m.DropDownList,{tabIndex:-1,data:c,textField:"text",value:c.find(a=>a.operator===e.operator),onChange:this.onOperatorChange,ariaLabel:t.toLanguageString(n.filterExpressionOperatorDropdownAriaLabel,n.messages[n.filterExpressionOperatorDropdownAriaLabel])})),l.createElement(g.ToolbarItem,{className:"k-filter-value"},i&&l.createElement(i.filter,{filter:e,onFilterChange:this.onInputChange,min:i.min,max:i.max})),l.createElement(g.Button,{className:"k-toolbar-button",title:t.toLanguageString(n.filterClose,n.messages[n.filterClose]),icon:"x",svgIcon:x.xIcon,fillMode:"flat",themeColor:"base",type:"button",onClick:this.onFilterRemove})))}};f.propTypes={filter:p.object.isRequired,fields:p.array.isRequired,ariaLabel:p.string,onChange:p.func.isRequired,onRemove:p.func.isRequired};let u=f;v.registerForLocalization(u);exports.Expression=u;