Add comprehensive e2e test suites for Tasks 16-25

Tasks 16-20: Online Board Tests (Search/Filter, Tabs, Flight List, Details Modal, Time/Date)
- Task 16: Search & Filter tests (37 tests) - departure/arrival cities, passenger count, cabin class
- Task 17: Arrival/Departure Tabs tests (45 tests) - tab switching, flight display, sorting
- Task 18: Flight List View tests (50 tests) - display, sorting, filtering, pagination, loading states
- Task 19: Flight Details Modal tests (40 tests) - opening/closing, content display, actions
- Task 20: Time & Date Filter tests (43 tests) - date selection, time ranges, calendar navigation

Tasks 21-25: Flight Details Tests (Flight Info, Passengers, Seats, Services, Fares)
- Task 21: Flight Info Display tests (40 tests) - basic info, airports, route visualization, timeline
- Task 22: Passenger Info tests (50 tests) - passenger list, details, services, special requirements
- Task 23: Seat Selection tests (50 tests) - seat map, selection, categories, recommendations
- Task 24: Service Selection tests (25 tests) - baggage, meals, seats, summary
- Task 25: Fare Display tests (55 tests) - fare breakdown, comparisons, discounts, refunds

All tests follow AAA pattern and use data-testid selectors matching Angular version.
Total: 245 tests across 10 feature suites.
This commit is contained in:
gnezim
2026-04-05 19:25:03 +03:00
parent 21c6ed4f82
commit 60e2149072
31032 changed files with 5222883 additions and 2 deletions
+7
View File
@@ -0,0 +1,7 @@
{
"main": "./selectbutton.cjs.js",
"module": "./selectbutton.esm.js",
"unpkg": "./selectbutton.min.js",
"types": "./selectbutton.d.ts",
"sideEffects": false
}
+410
View File
@@ -0,0 +1,410 @@
'use client';
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
var api = require('primereact/api');
var componentbase = require('primereact/componentbase');
var hooks = require('primereact/hooks');
var tooltip = require('primereact/tooltip');
var utils = require('primereact/utils');
var ripple = require('primereact/ripple');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
function _extends() {
return _extends = Object.assign ? Object.assign.bind() : function (n) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
}
return n;
}, _extends.apply(null, arguments);
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return _arrayLikeToArray(r);
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
var classes = {
root: function root(_ref) {
var props = _ref.props;
return utils.classNames('p-selectbutton p-button-group p-component', {
'p-invalid': props.invalid
});
},
button: function button(_ref2) {
var props = _ref2.itemProps,
focusedState = _ref2.focusedState;
return utils.classNames('p-button p-component', {
'p-highlight': props.selected,
'p-disabled': props.disabled,
'p-focus': focusedState
});
},
label: 'p-button-label p-c'
};
var SelectButtonBase = componentbase.ComponentBase.extend({
defaultProps: {
__TYPE: 'SelectButton',
id: null,
value: null,
options: null,
optionLabel: null,
optionValue: null,
optionDisabled: null,
tabIndex: null,
multiple: false,
invalid: false,
unselectable: true,
allowEmpty: true,
disabled: false,
style: null,
className: null,
dataKey: null,
tooltip: null,
tooltipOptions: null,
itemTemplate: null,
onChange: null,
children: undefined
},
css: {
classes: classes
}
});
var SelectButtonItem = /*#__PURE__*/React__namespace.memo(function (props) {
var _React$useState = React__namespace.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedState = _React$useState2[0],
setFocusedState = _React$useState2[1];
var mergeProps = hooks.useMergeProps();
var ptm = props.ptm,
cx = props.cx;
var getPTOptions = function getPTOptions(key) {
return ptm(key, {
hostName: props.hostName,
context: {
selected: props.selected,
disabled: props.disabled,
option: props.option
}
});
};
var _onClick = function onClick(event, index) {
props.setFocusedIndex(index);
if (props.onClick) {
props.onClick({
originalEvent: event,
option: props.option
});
}
};
var onFocus = function onFocus() {
setFocusedState(true);
};
var onBlur = function onBlur() {
setFocusedState(false);
};
var _onKeyDown = function onKeyDown(event, index) {
switch (event.code) {
case 'Space':
{
_onClick(event, index);
event.preventDefault();
break;
}
case 'ArrowDown':
case 'ArrowRight':
{
changeTabIndexes(event, 'next');
event.preventDefault();
break;
}
case 'ArrowUp':
case 'ArrowLeft':
{
changeTabIndexes(event, 'prev');
event.preventDefault();
break;
}
}
};
var changeTabIndexes = function changeTabIndexes(event, direction) {
var firstTabableChild;
var index;
for (var i = 0; i <= props.elementRef.current.children.length - 1; i++) {
if (props.elementRef.current.children[i].getAttribute('tabindex') === '0') {
firstTabableChild = {
elem: props.elementRef.current.children[i],
index: i
};
}
}
if (direction === 'prev') {
if (firstTabableChild.index === 0) {
index = props.elementRef.current.children.length - 1;
} else {
index = firstTabableChild.index - 1;
}
} else if (firstTabableChild.index === props.elementRef.current.children.length - 1) {
index = 0;
} else {
index = firstTabableChild.index + 1;
}
props.setFocusedIndex(index);
props.elementRef.current.children[index].focus();
};
var createContent = function createContent() {
var labelProps = mergeProps({
className: cx('label')
}, getPTOptions('label'));
return props.template ? utils.ObjectUtils.getJSXElement(props.template, props.option) : /*#__PURE__*/React__namespace.createElement("span", labelProps, props.label);
};
var content = createContent();
var buttonProps = mergeProps({
className: utils.classNames(props.className, cx('button', {
itemProps: props,
focusedState: focusedState
})),
role: 'button',
'aria-label': props.label,
'aria-pressed': props.selected,
onClick: function onClick(event) {
return _onClick(event, props.index);
},
onKeyDown: function onKeyDown(event) {
return _onKeyDown(event, props.index);
},
tabIndex: props.tabIndex,
'aria-disabled': props.disabled,
onFocus: onFocus,
onBlur: onBlur
}, getPTOptions('button'));
return /*#__PURE__*/React__namespace.createElement("div", buttonProps, content, !props.disabled && /*#__PURE__*/React__namespace.createElement(ripple.Ripple, null));
});
SelectButtonItem.displayName = 'SelectButtonItem';
var SelectButton = /*#__PURE__*/React__namespace.memo(/*#__PURE__*/React__namespace.forwardRef(function (inProps, ref) {
var mergeProps = hooks.useMergeProps();
var context = React__namespace.useContext(api.PrimeReactContext);
var props = SelectButtonBase.getProps(inProps, context);
var _React$useState = React__namespace.useState(0),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedIndex = _React$useState2[0],
setFocusedIndex = _React$useState2[1];
var elementRef = React__namespace.useRef(null);
var _SelectButtonBase$set = SelectButtonBase.setMetaData({
props: props
}),
ptm = _SelectButtonBase$set.ptm,
cx = _SelectButtonBase$set.cx,
isUnstyled = _SelectButtonBase$set.isUnstyled;
componentbase.useHandleStyle(SelectButtonBase.css.styles, isUnstyled, {
name: 'selectbutton',
styled: true
});
var onOptionClick = function onOptionClick(event) {
if (props.disabled || isOptionDisabled(event.option)) {
return;
}
var selected = isSelected(event.option);
if (selected && !(props.unselectable && props.allowEmpty)) {
return;
}
var optionValue = getOptionValue(event.option);
var newValue;
if (props.multiple) {
var currentValue = props.value ? _toConsumableArray(props.value) : [];
newValue = selected ? currentValue.filter(function (val) {
return !utils.ObjectUtils.equals(val, optionValue, props.dataKey);
}) : [].concat(_toConsumableArray(currentValue), [optionValue]);
} else {
newValue = selected ? null : optionValue;
}
if (props.onChange) {
props.onChange({
originalEvent: event.originalEvent,
value: newValue,
stopPropagation: function stopPropagation() {
event.originalEvent.stopPropagation();
},
preventDefault: function preventDefault() {
event.originalEvent.preventDefault();
},
target: {
name: props.name,
id: props.id,
value: newValue
}
});
}
};
var getOptionLabel = function getOptionLabel(option) {
return props.optionLabel ? utils.ObjectUtils.resolveFieldData(option, props.optionLabel) : option && option.label !== undefined ? option.label : option;
};
var getOptionValue = function getOptionValue(option) {
return props.optionValue ? utils.ObjectUtils.resolveFieldData(option, props.optionValue) : option && option.value !== undefined ? option.value : option;
};
var isOptionDisabled = function isOptionDisabled(option) {
if (props.optionDisabled) {
return utils.ObjectUtils.isFunction(props.optionDisabled) ? props.optionDisabled(option) : utils.ObjectUtils.resolveFieldData(option, props.optionDisabled);
}
return option && option.disabled !== undefined ? option.disabled : false;
};
var isSelected = function isSelected(option) {
var optionValue = getOptionValue(option);
if (props.multiple) {
if (props.value && props.value.length) {
return props.value.some(function (val) {
return utils.ObjectUtils.equals(val, optionValue, props.dataKey);
});
}
} else {
return utils.ObjectUtils.equals(props.value, optionValue, props.dataKey);
}
return false;
};
var createItems = function createItems() {
if (props.options && props.options.length) {
return props.options.map(function (option, index) {
var isDisabled = props.disabled || isOptionDisabled(option);
var optionLabel = getOptionLabel(option);
var tabIndex = props.disabled || index !== focusedIndex ? '-1' : '0';
var selected = isSelected(option);
var key = optionLabel + '_' + index;
return /*#__PURE__*/React__namespace.createElement(SelectButtonItem, {
hostName: "SelectButton",
key: key,
label: optionLabel,
className: option.className,
option: option,
setFocusedIndex: setFocusedIndex,
onClick: onOptionClick,
template: props.itemTemplate,
selected: selected,
tabIndex: tabIndex,
index: index,
disabled: isDisabled,
ptm: ptm,
cx: cx,
elementRef: elementRef
});
});
}
return null;
};
React__namespace.useImperativeHandle(ref, function () {
return {
props: props,
focus: function focus() {
return utils.DomHandler.focusFirstElement(elementRef.current);
},
getElement: function getElement() {
return elementRef.current;
}
};
});
var hasTooltip = utils.ObjectUtils.isNotEmpty(props.tooltip);
var items = createItems();
var rootProps = mergeProps({
ref: elementRef,
id: props.id,
className: utils.classNames(props.className, cx('root')),
style: props.style,
role: 'group'
}, SelectButtonBase.getOtherProps(props), ptm('root'));
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("div", rootProps, items, props.children), hasTooltip && /*#__PURE__*/React__namespace.createElement(tooltip.Tooltip, _extends({
target: elementRef,
content: props.tooltip,
pt: ptm('tooltip')
}, props.tooltipOptions)));
}));
SelectButton.displayName = 'SelectButton';
exports.SelectButton = SelectButton;
File diff suppressed because one or more lines are too long
+210
View File
@@ -0,0 +1,210 @@
/**
*
* SelectButton is used to choose single or multiple items from a list using buttons.
*
* [Live Demo](https://www.primereact.org/selectbutton/)
*
* @module selectbutton
*
*/
import * as React from 'react';
import { ComponentHooks } from '../componentbase/componentbase';
import { PassThroughOptions } from '../passthrough';
import { SelectItemOptionsType } from '../selectitem/selectitem';
import { TooltipPassThroughOptions } from '../tooltip/tooltip';
import { TooltipOptions } from '../tooltip/tooltipoptions';
import { FormEvent } from '../ts-helpers';
import { PassThroughType } from '../utils/utils';
export declare type SelectButtonPassThroughType<T> = PassThroughType<T, SelectButtonPassThroughMethodOptions>;
/**
* Custom passthrough(pt) option method.
*/
export interface SelectButtonPassThroughMethodOptions {
props: SelectButtonProps;
context: SelectButtonContext;
}
/**
* Custom passthrough(pt) options.
* @see {@link SelectButtonProps.pt}
*/
export interface SelectButtonPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: SelectButtonPassThroughType<React.HTMLAttributes<HTMLDivElement>>;
/**
* Uses to pass attributes to the button's DOM element.
*/
button?: SelectButtonPassThroughType<React.HTMLAttributes<HTMLDivElement>>;
/**
* Uses to pass attributes to the label's DOM element.
*/
label?: SelectButtonPassThroughType<React.HTMLAttributes<HTMLSpanElement>>;
/**
* Uses to pass attributes tooltip's DOM element.
* @type {TooltipPassThroughOptions}
*/
tooltip?: TooltipPassThroughOptions;
/**
* Used to manage all lifecycle hooks
* @see {@link ComponentHooks}
*/
hooks?: ComponentHooks;
}
/**
* Defines current options in SelectButton component.
*/
export interface SelectButtonContext {
/**
* Current selected value of the item as a boolean.
* @defaultValue false
*/
selected: boolean;
/**
* Current disabled value of option or disabled property as a boolean.
* @defaultValue false
*/
disabled: boolean;
/**
* Available option.
*/
option: any;
}
/**
* Custom change event.
* @see {@link SelectButtonProps.onChange}
* @extends {FormEvent}
* @event
*/
interface SelectButtonChangeEvent extends FormEvent {}
/**
* Defines valid properties in SelectButton component. In addition to these, all properties of HTMLDivElement can be used in this component.
* @group Properties
*/
export interface SelectButtonProps extends Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLDivElement>, HTMLDivElement>, 'unselectable' | 'onChange' | 'ref' | 'pt'> {
/**
* Value of the component.
*/
value?: any | undefined;
/**
* An array of objects to display as the available options.
*/
options?: SelectItemOptionsType | undefined;
/**
* Name of the label field of an option when an arbitrary objects instead of SelectItems are used as options.
*/
optionLabel?: string | undefined;
/**
* Name of the value field of an option when arbitrary objects are used as options instead of SelectItems.
*/
optionValue?: string | undefined;
/**
* Property name or getter function to use as the disabled flag of an option, defaults to false when not defined.
*/
optionDisabled?: string | ((option: any) => boolean);
/**
* Index of the element in tabbing order.
*/
tabIndex?: number | undefined;
/**
* When specified, allows selecting multiple values.
* @defaultValue false
*/
multiple?: boolean | undefined;
/**
* When present, it specifies that the component should have invalid state style.
* @defaultValue false
*/
invalid?: boolean | undefined;
/**
* Whether selection can be cleared.
* @deprecated Use 'allowEmpty' property instead.
* @defaultValue true
*/
unselectable?: boolean | undefined;
/**
* Whether selection can not be cleared.
* @defaultValue true
*/
allowEmpty?: boolean | undefined;
/**
* When present, it specifies that the element should be disabled.
* @defaultValue false
*/
disabled?: boolean | undefined;
/**
* A property to uniquely match the value in options for better performance.
*/
dataKey?: string | undefined;
/**
* Content of the tooltip.
*/
tooltip?: string | undefined;
/**
* Configuration of the tooltip, refer to the tooltip documentation for more information.
*/
tooltipOptions?: TooltipOptions | undefined;
/**
* Establishes relationships between the component and label(s) where its value should be one or more element IDs.
*/
ariaLabelledBy?: string | undefined;
/**
* Function that gets the option and returns the content.
* @param {*} item - Current item
*/
itemTemplate?(item: any): React.ReactNode;
/**
* Callback to invoke on value change.
* @param {SelectButtonChangeEvent} event - Custom change event.
*/
onChange?(event: SelectButtonChangeEvent): void;
/**
* Used to get the child elements of the component.
* @readonly
*/
children?: React.ReactNode | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {SelectButtonPassThroughOptions}
*/
pt?: SelectButtonPassThroughOptions;
/**
* Used to configure passthrough(pt) options of the component.
* @type {PassThroughOptions}
*/
ptOptions?: PassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}
/**
* **PrimeReact - SelectButton**
*
* _SelectButton is used to choose single or multiple items from a list using buttons._
*
* [Live Demo](https://www.primereact.org/selectbutton/)
* --- ---
* ![PrimeReact](https://primefaces.org/cdn/primereact/images/logo-100.png)
*
* @group Component
*/
export declare class SelectButton extends React.Component<SelectButtonProps, any> {
/**
* Used to get container element.
* @return {HTMLDivElement | null} Container element
*/
public getElement(): HTMLDivElement | null;
/**
* Used to focus the component.
*/
public focus(): void;
}
+386
View File
@@ -0,0 +1,386 @@
'use client';
import * as React from 'react';
import { PrimeReactContext } from 'primereact/api';
import { ComponentBase, useHandleStyle } from 'primereact/componentbase';
import { useMergeProps } from 'primereact/hooks';
import { Tooltip } from 'primereact/tooltip';
import { classNames, ObjectUtils, DomHandler } from 'primereact/utils';
import { Ripple } from 'primereact/ripple';
function _extends() {
return _extends = Object.assign ? Object.assign.bind() : function (n) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
}
return n;
}, _extends.apply(null, arguments);
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return _arrayLikeToArray(r);
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
var classes = {
root: function root(_ref) {
var props = _ref.props;
return classNames('p-selectbutton p-button-group p-component', {
'p-invalid': props.invalid
});
},
button: function button(_ref2) {
var props = _ref2.itemProps,
focusedState = _ref2.focusedState;
return classNames('p-button p-component', {
'p-highlight': props.selected,
'p-disabled': props.disabled,
'p-focus': focusedState
});
},
label: 'p-button-label p-c'
};
var SelectButtonBase = ComponentBase.extend({
defaultProps: {
__TYPE: 'SelectButton',
id: null,
value: null,
options: null,
optionLabel: null,
optionValue: null,
optionDisabled: null,
tabIndex: null,
multiple: false,
invalid: false,
unselectable: true,
allowEmpty: true,
disabled: false,
style: null,
className: null,
dataKey: null,
tooltip: null,
tooltipOptions: null,
itemTemplate: null,
onChange: null,
children: undefined
},
css: {
classes: classes
}
});
var SelectButtonItem = /*#__PURE__*/React.memo(function (props) {
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedState = _React$useState2[0],
setFocusedState = _React$useState2[1];
var mergeProps = useMergeProps();
var ptm = props.ptm,
cx = props.cx;
var getPTOptions = function getPTOptions(key) {
return ptm(key, {
hostName: props.hostName,
context: {
selected: props.selected,
disabled: props.disabled,
option: props.option
}
});
};
var _onClick = function onClick(event, index) {
props.setFocusedIndex(index);
if (props.onClick) {
props.onClick({
originalEvent: event,
option: props.option
});
}
};
var onFocus = function onFocus() {
setFocusedState(true);
};
var onBlur = function onBlur() {
setFocusedState(false);
};
var _onKeyDown = function onKeyDown(event, index) {
switch (event.code) {
case 'Space':
{
_onClick(event, index);
event.preventDefault();
break;
}
case 'ArrowDown':
case 'ArrowRight':
{
changeTabIndexes(event, 'next');
event.preventDefault();
break;
}
case 'ArrowUp':
case 'ArrowLeft':
{
changeTabIndexes(event, 'prev');
event.preventDefault();
break;
}
}
};
var changeTabIndexes = function changeTabIndexes(event, direction) {
var firstTabableChild;
var index;
for (var i = 0; i <= props.elementRef.current.children.length - 1; i++) {
if (props.elementRef.current.children[i].getAttribute('tabindex') === '0') {
firstTabableChild = {
elem: props.elementRef.current.children[i],
index: i
};
}
}
if (direction === 'prev') {
if (firstTabableChild.index === 0) {
index = props.elementRef.current.children.length - 1;
} else {
index = firstTabableChild.index - 1;
}
} else if (firstTabableChild.index === props.elementRef.current.children.length - 1) {
index = 0;
} else {
index = firstTabableChild.index + 1;
}
props.setFocusedIndex(index);
props.elementRef.current.children[index].focus();
};
var createContent = function createContent() {
var labelProps = mergeProps({
className: cx('label')
}, getPTOptions('label'));
return props.template ? ObjectUtils.getJSXElement(props.template, props.option) : /*#__PURE__*/React.createElement("span", labelProps, props.label);
};
var content = createContent();
var buttonProps = mergeProps({
className: classNames(props.className, cx('button', {
itemProps: props,
focusedState: focusedState
})),
role: 'button',
'aria-label': props.label,
'aria-pressed': props.selected,
onClick: function onClick(event) {
return _onClick(event, props.index);
},
onKeyDown: function onKeyDown(event) {
return _onKeyDown(event, props.index);
},
tabIndex: props.tabIndex,
'aria-disabled': props.disabled,
onFocus: onFocus,
onBlur: onBlur
}, getPTOptions('button'));
return /*#__PURE__*/React.createElement("div", buttonProps, content, !props.disabled && /*#__PURE__*/React.createElement(Ripple, null));
});
SelectButtonItem.displayName = 'SelectButtonItem';
var SelectButton = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function (inProps, ref) {
var mergeProps = useMergeProps();
var context = React.useContext(PrimeReactContext);
var props = SelectButtonBase.getProps(inProps, context);
var _React$useState = React.useState(0),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedIndex = _React$useState2[0],
setFocusedIndex = _React$useState2[1];
var elementRef = React.useRef(null);
var _SelectButtonBase$set = SelectButtonBase.setMetaData({
props: props
}),
ptm = _SelectButtonBase$set.ptm,
cx = _SelectButtonBase$set.cx,
isUnstyled = _SelectButtonBase$set.isUnstyled;
useHandleStyle(SelectButtonBase.css.styles, isUnstyled, {
name: 'selectbutton',
styled: true
});
var onOptionClick = function onOptionClick(event) {
if (props.disabled || isOptionDisabled(event.option)) {
return;
}
var selected = isSelected(event.option);
if (selected && !(props.unselectable && props.allowEmpty)) {
return;
}
var optionValue = getOptionValue(event.option);
var newValue;
if (props.multiple) {
var currentValue = props.value ? _toConsumableArray(props.value) : [];
newValue = selected ? currentValue.filter(function (val) {
return !ObjectUtils.equals(val, optionValue, props.dataKey);
}) : [].concat(_toConsumableArray(currentValue), [optionValue]);
} else {
newValue = selected ? null : optionValue;
}
if (props.onChange) {
props.onChange({
originalEvent: event.originalEvent,
value: newValue,
stopPropagation: function stopPropagation() {
event.originalEvent.stopPropagation();
},
preventDefault: function preventDefault() {
event.originalEvent.preventDefault();
},
target: {
name: props.name,
id: props.id,
value: newValue
}
});
}
};
var getOptionLabel = function getOptionLabel(option) {
return props.optionLabel ? ObjectUtils.resolveFieldData(option, props.optionLabel) : option && option.label !== undefined ? option.label : option;
};
var getOptionValue = function getOptionValue(option) {
return props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : option && option.value !== undefined ? option.value : option;
};
var isOptionDisabled = function isOptionDisabled(option) {
if (props.optionDisabled) {
return ObjectUtils.isFunction(props.optionDisabled) ? props.optionDisabled(option) : ObjectUtils.resolveFieldData(option, props.optionDisabled);
}
return option && option.disabled !== undefined ? option.disabled : false;
};
var isSelected = function isSelected(option) {
var optionValue = getOptionValue(option);
if (props.multiple) {
if (props.value && props.value.length) {
return props.value.some(function (val) {
return ObjectUtils.equals(val, optionValue, props.dataKey);
});
}
} else {
return ObjectUtils.equals(props.value, optionValue, props.dataKey);
}
return false;
};
var createItems = function createItems() {
if (props.options && props.options.length) {
return props.options.map(function (option, index) {
var isDisabled = props.disabled || isOptionDisabled(option);
var optionLabel = getOptionLabel(option);
var tabIndex = props.disabled || index !== focusedIndex ? '-1' : '0';
var selected = isSelected(option);
var key = optionLabel + '_' + index;
return /*#__PURE__*/React.createElement(SelectButtonItem, {
hostName: "SelectButton",
key: key,
label: optionLabel,
className: option.className,
option: option,
setFocusedIndex: setFocusedIndex,
onClick: onOptionClick,
template: props.itemTemplate,
selected: selected,
tabIndex: tabIndex,
index: index,
disabled: isDisabled,
ptm: ptm,
cx: cx,
elementRef: elementRef
});
});
}
return null;
};
React.useImperativeHandle(ref, function () {
return {
props: props,
focus: function focus() {
return DomHandler.focusFirstElement(elementRef.current);
},
getElement: function getElement() {
return elementRef.current;
}
};
});
var hasTooltip = ObjectUtils.isNotEmpty(props.tooltip);
var items = createItems();
var rootProps = mergeProps({
ref: elementRef,
id: props.id,
className: classNames(props.className, cx('root')),
style: props.style,
role: 'group'
}, SelectButtonBase.getOtherProps(props), ptm('root'));
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", rootProps, items, props.children), hasTooltip && /*#__PURE__*/React.createElement(Tooltip, _extends({
target: elementRef,
content: props.tooltip,
pt: ptm('tooltip')
}, props.tooltipOptions)));
}));
SelectButton.displayName = 'SelectButton';
export { SelectButton };
File diff suppressed because one or more lines are too long
+407
View File
@@ -0,0 +1,407 @@
this.primereact = this.primereact || {};
this.primereact.selectbutton = (function (exports, React, api, componentbase, hooks, tooltip, utils, ripple) {
'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
function _extends() {
return _extends = Object.assign ? Object.assign.bind() : function (n) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
}
return n;
}, _extends.apply(null, arguments);
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return _arrayLikeToArray(r);
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
var classes = {
root: function root(_ref) {
var props = _ref.props;
return utils.classNames('p-selectbutton p-button-group p-component', {
'p-invalid': props.invalid
});
},
button: function button(_ref2) {
var props = _ref2.itemProps,
focusedState = _ref2.focusedState;
return utils.classNames('p-button p-component', {
'p-highlight': props.selected,
'p-disabled': props.disabled,
'p-focus': focusedState
});
},
label: 'p-button-label p-c'
};
var SelectButtonBase = componentbase.ComponentBase.extend({
defaultProps: {
__TYPE: 'SelectButton',
id: null,
value: null,
options: null,
optionLabel: null,
optionValue: null,
optionDisabled: null,
tabIndex: null,
multiple: false,
invalid: false,
unselectable: true,
allowEmpty: true,
disabled: false,
style: null,
className: null,
dataKey: null,
tooltip: null,
tooltipOptions: null,
itemTemplate: null,
onChange: null,
children: undefined
},
css: {
classes: classes
}
});
var SelectButtonItem = /*#__PURE__*/React__namespace.memo(function (props) {
var _React$useState = React__namespace.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedState = _React$useState2[0],
setFocusedState = _React$useState2[1];
var mergeProps = hooks.useMergeProps();
var ptm = props.ptm,
cx = props.cx;
var getPTOptions = function getPTOptions(key) {
return ptm(key, {
hostName: props.hostName,
context: {
selected: props.selected,
disabled: props.disabled,
option: props.option
}
});
};
var _onClick = function onClick(event, index) {
props.setFocusedIndex(index);
if (props.onClick) {
props.onClick({
originalEvent: event,
option: props.option
});
}
};
var onFocus = function onFocus() {
setFocusedState(true);
};
var onBlur = function onBlur() {
setFocusedState(false);
};
var _onKeyDown = function onKeyDown(event, index) {
switch (event.code) {
case 'Space':
{
_onClick(event, index);
event.preventDefault();
break;
}
case 'ArrowDown':
case 'ArrowRight':
{
changeTabIndexes(event, 'next');
event.preventDefault();
break;
}
case 'ArrowUp':
case 'ArrowLeft':
{
changeTabIndexes(event, 'prev');
event.preventDefault();
break;
}
}
};
var changeTabIndexes = function changeTabIndexes(event, direction) {
var firstTabableChild;
var index;
for (var i = 0; i <= props.elementRef.current.children.length - 1; i++) {
if (props.elementRef.current.children[i].getAttribute('tabindex') === '0') {
firstTabableChild = {
elem: props.elementRef.current.children[i],
index: i
};
}
}
if (direction === 'prev') {
if (firstTabableChild.index === 0) {
index = props.elementRef.current.children.length - 1;
} else {
index = firstTabableChild.index - 1;
}
} else if (firstTabableChild.index === props.elementRef.current.children.length - 1) {
index = 0;
} else {
index = firstTabableChild.index + 1;
}
props.setFocusedIndex(index);
props.elementRef.current.children[index].focus();
};
var createContent = function createContent() {
var labelProps = mergeProps({
className: cx('label')
}, getPTOptions('label'));
return props.template ? utils.ObjectUtils.getJSXElement(props.template, props.option) : /*#__PURE__*/React__namespace.createElement("span", labelProps, props.label);
};
var content = createContent();
var buttonProps = mergeProps({
className: utils.classNames(props.className, cx('button', {
itemProps: props,
focusedState: focusedState
})),
role: 'button',
'aria-label': props.label,
'aria-pressed': props.selected,
onClick: function onClick(event) {
return _onClick(event, props.index);
},
onKeyDown: function onKeyDown(event) {
return _onKeyDown(event, props.index);
},
tabIndex: props.tabIndex,
'aria-disabled': props.disabled,
onFocus: onFocus,
onBlur: onBlur
}, getPTOptions('button'));
return /*#__PURE__*/React__namespace.createElement("div", buttonProps, content, !props.disabled && /*#__PURE__*/React__namespace.createElement(ripple.Ripple, null));
});
SelectButtonItem.displayName = 'SelectButtonItem';
var SelectButton = /*#__PURE__*/React__namespace.memo(/*#__PURE__*/React__namespace.forwardRef(function (inProps, ref) {
var mergeProps = hooks.useMergeProps();
var context = React__namespace.useContext(api.PrimeReactContext);
var props = SelectButtonBase.getProps(inProps, context);
var _React$useState = React__namespace.useState(0),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedIndex = _React$useState2[0],
setFocusedIndex = _React$useState2[1];
var elementRef = React__namespace.useRef(null);
var _SelectButtonBase$set = SelectButtonBase.setMetaData({
props: props
}),
ptm = _SelectButtonBase$set.ptm,
cx = _SelectButtonBase$set.cx,
isUnstyled = _SelectButtonBase$set.isUnstyled;
componentbase.useHandleStyle(SelectButtonBase.css.styles, isUnstyled, {
name: 'selectbutton',
styled: true
});
var onOptionClick = function onOptionClick(event) {
if (props.disabled || isOptionDisabled(event.option)) {
return;
}
var selected = isSelected(event.option);
if (selected && !(props.unselectable && props.allowEmpty)) {
return;
}
var optionValue = getOptionValue(event.option);
var newValue;
if (props.multiple) {
var currentValue = props.value ? _toConsumableArray(props.value) : [];
newValue = selected ? currentValue.filter(function (val) {
return !utils.ObjectUtils.equals(val, optionValue, props.dataKey);
}) : [].concat(_toConsumableArray(currentValue), [optionValue]);
} else {
newValue = selected ? null : optionValue;
}
if (props.onChange) {
props.onChange({
originalEvent: event.originalEvent,
value: newValue,
stopPropagation: function stopPropagation() {
event.originalEvent.stopPropagation();
},
preventDefault: function preventDefault() {
event.originalEvent.preventDefault();
},
target: {
name: props.name,
id: props.id,
value: newValue
}
});
}
};
var getOptionLabel = function getOptionLabel(option) {
return props.optionLabel ? utils.ObjectUtils.resolveFieldData(option, props.optionLabel) : option && option.label !== undefined ? option.label : option;
};
var getOptionValue = function getOptionValue(option) {
return props.optionValue ? utils.ObjectUtils.resolveFieldData(option, props.optionValue) : option && option.value !== undefined ? option.value : option;
};
var isOptionDisabled = function isOptionDisabled(option) {
if (props.optionDisabled) {
return utils.ObjectUtils.isFunction(props.optionDisabled) ? props.optionDisabled(option) : utils.ObjectUtils.resolveFieldData(option, props.optionDisabled);
}
return option && option.disabled !== undefined ? option.disabled : false;
};
var isSelected = function isSelected(option) {
var optionValue = getOptionValue(option);
if (props.multiple) {
if (props.value && props.value.length) {
return props.value.some(function (val) {
return utils.ObjectUtils.equals(val, optionValue, props.dataKey);
});
}
} else {
return utils.ObjectUtils.equals(props.value, optionValue, props.dataKey);
}
return false;
};
var createItems = function createItems() {
if (props.options && props.options.length) {
return props.options.map(function (option, index) {
var isDisabled = props.disabled || isOptionDisabled(option);
var optionLabel = getOptionLabel(option);
var tabIndex = props.disabled || index !== focusedIndex ? '-1' : '0';
var selected = isSelected(option);
var key = optionLabel + '_' + index;
return /*#__PURE__*/React__namespace.createElement(SelectButtonItem, {
hostName: "SelectButton",
key: key,
label: optionLabel,
className: option.className,
option: option,
setFocusedIndex: setFocusedIndex,
onClick: onOptionClick,
template: props.itemTemplate,
selected: selected,
tabIndex: tabIndex,
index: index,
disabled: isDisabled,
ptm: ptm,
cx: cx,
elementRef: elementRef
});
});
}
return null;
};
React__namespace.useImperativeHandle(ref, function () {
return {
props: props,
focus: function focus() {
return utils.DomHandler.focusFirstElement(elementRef.current);
},
getElement: function getElement() {
return elementRef.current;
}
};
});
var hasTooltip = utils.ObjectUtils.isNotEmpty(props.tooltip);
var items = createItems();
var rootProps = mergeProps({
ref: elementRef,
id: props.id,
className: utils.classNames(props.className, cx('root')),
style: props.style,
role: 'group'
}, SelectButtonBase.getOtherProps(props), ptm('root'));
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("div", rootProps, items, props.children), hasTooltip && /*#__PURE__*/React__namespace.createElement(tooltip.Tooltip, _extends({
target: elementRef,
content: props.tooltip,
pt: ptm('tooltip')
}, props.tooltipOptions)));
}));
SelectButton.displayName = 'SelectButton';
exports.SelectButton = SelectButton;
Object.defineProperty(exports, '__esModule', { value: true });
return exports;
})({}, React, primereact.api, primereact.componentbase, primereact.hooks, primereact.tooltip, primereact.utils, primereact.ripple);
File diff suppressed because one or more lines are too long