@pushwoosh/dumb-components 4.17.1 → 4.18.0

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.
@@ -0,0 +1,4 @@
1
+ import { type ReactElement } from 'react';
2
+ import type { PillSelectorProps } from './types';
3
+ /** Row of pills with an optional field-box header; `mode="radio"` picks one value, `mode="checkbox"` any number. */
4
+ export declare function PillSelector(props: PillSelectorProps): ReactElement;
@@ -0,0 +1,86 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useRef } from 'react';
3
+ import { Text } from '@pushwoosh/kit-typography';
4
+ import { Pill } from './components/Pill';
5
+ import { Container, PillRow } from './styles';
6
+ const STEP_BY_KEY = {
7
+ ArrowRight: 1,
8
+ ArrowDown: 1,
9
+ ArrowLeft: -1,
10
+ ArrowUp: -1
11
+ };
12
+ /** Row of pills with an optional field-box header; `mode="radio"` picks one value, `mode="checkbox"` any number. */
13
+ export function PillSelector(props) {
14
+ const {
15
+ title,
16
+ items,
17
+ isDisabled = false,
18
+ isReadOnly = false,
19
+ className,
20
+ 'aria-label': ariaLabel
21
+ } = props;
22
+ const isRadio = props.mode !== 'checkbox';
23
+ const hasTitle = title !== undefined && title !== null && title !== false;
24
+ const titleId = useId();
25
+ const pillsRef = useRef([]);
26
+ const isSelected = value => props.mode === 'checkbox' ? props.value.includes(value) : props.value === value;
27
+ const isItemDisabled = item => isDisabled || !!item.isDisabled;
28
+ const select = value => {
29
+ if (isReadOnly) {
30
+ return;
31
+ }
32
+ if (props.mode === 'checkbox') {
33
+ props.onChange(isSelected(value) ? props.value.filter(selected => selected !== value) : [...props.value, value]);
34
+ } else if (props.value !== value) {
35
+ props.onChange(value);
36
+ }
37
+ };
38
+ const enabledIndexes = items.flatMap((item, index) => isItemDisabled(item) ? [] : [index]);
39
+ const selectedIndex = enabledIndexes.find(index => isSelected(items[index].value));
40
+ const tabStopIndex = selectedIndex ?? enabledIndexes[0];
41
+ const moveSelection = (event, index) => {
42
+ const position = enabledIndexes.indexOf(index);
43
+ let target;
44
+ if (event.key in STEP_BY_KEY) {
45
+ const count = enabledIndexes.length;
46
+ target = enabledIndexes[(position + STEP_BY_KEY[event.key] + count) % count];
47
+ } else if (event.key === 'Home') {
48
+ target = enabledIndexes[0];
49
+ } else if (event.key === 'End') {
50
+ target = enabledIndexes[enabledIndexes.length - 1];
51
+ }
52
+ if (target === undefined) {
53
+ return;
54
+ }
55
+ event.preventDefault();
56
+ pillsRef.current[target]?.focus();
57
+ select(items[target].value);
58
+ };
59
+ return _jsxs(Container, {
60
+ className: className,
61
+ children: [hasTitle && _jsx(Text, {
62
+ id: titleId,
63
+ "$variant": "h4",
64
+ children: title
65
+ }), _jsx(PillRow, {
66
+ role: isRadio ? 'radiogroup' : 'group',
67
+ "aria-labelledby": hasTitle ? titleId : undefined,
68
+ "aria-label": ariaLabel,
69
+ "aria-disabled": isDisabled || undefined,
70
+ "aria-readonly": isRadio && isReadOnly ? true : undefined,
71
+ children: items.map((item, index) => _jsx(Pill, {
72
+ ref: element => {
73
+ pillsRef.current[index] = element;
74
+ },
75
+ role: isRadio ? 'radio' : undefined,
76
+ tabIndex: isRadio && index !== tabStopIndex ? -1 : 0,
77
+ isSelected: isSelected(item.value),
78
+ isDisabled: isItemDisabled(item),
79
+ isReadOnly: isReadOnly,
80
+ onClick: () => select(item.value),
81
+ onKeyDown: isRadio ? event => moveSelection(event, index) : undefined,
82
+ children: item.label
83
+ }, item.value))
84
+ })]
85
+ });
86
+ }
@@ -0,0 +1,7 @@
1
+ /** Selectable pill: a toggle `<button>`, filled when `isSelected`; usually rendered by `PillSelector`. */
2
+ export declare const Pill: import("react").ForwardRefExoticComponent<Omit<import("react").ButtonHTMLAttributes<HTMLButtonElement>, "role" | "disabled"> & {
3
+ isSelected?: boolean;
4
+ isDisabled?: boolean;
5
+ isReadOnly?: boolean;
6
+ role?: "radio";
7
+ } & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from 'react';
3
+ import { PillStyled } from './styles';
4
+ /** Selectable pill: a toggle `<button>`, filled when `isSelected`; usually rendered by `PillSelector`. */
5
+ export const Pill = forwardRef(({
6
+ isSelected = false,
7
+ isDisabled = false,
8
+ isReadOnly = false,
9
+ role,
10
+ onClick,
11
+ children,
12
+ ...rest
13
+ }, ref) => _jsx(PillStyled, {
14
+ ...rest,
15
+ ref: ref,
16
+ type: "button",
17
+ role: role,
18
+ "aria-checked": role === 'radio' ? isSelected : undefined,
19
+ "aria-pressed": role === 'radio' ? undefined : isSelected,
20
+ disabled: isDisabled,
21
+ "$isSelected": isSelected,
22
+ "$isMuted": isDisabled || isReadOnly,
23
+ "$isDisabled": isDisabled,
24
+ onClick: isReadOnly ? undefined : onClick,
25
+ children: children
26
+ }));
27
+ Pill.displayName = 'Pill';
@@ -0,0 +1,2 @@
1
+ export { Pill } from './Pill';
2
+ export type { PillProps } from './types';
@@ -0,0 +1 @@
1
+ export { Pill } from './Pill';
@@ -0,0 +1,4 @@
1
+ import type { PillStyledProps } from './types';
2
+ export declare const PillStyled: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Merged<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "style"> & {
3
+ style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
4
+ }, PillStyledProps>> & string;
@@ -0,0 +1,52 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { Color, FontFamily, FontSize, FontWeight, LineHeight, ShapeRadius } from '@pushwoosh/kit-constants';
3
+ const palette = {
4
+ active: {
5
+ on: {
6
+ color: Color.CLEAR,
7
+ background: Color.PRIMARY
8
+ },
9
+ off: {
10
+ color: Color.PRIMARY,
11
+ background: Color.BRIGHT_LIGHT
12
+ }
13
+ },
14
+ hover: {
15
+ on: {
16
+ color: Color.CLEAR,
17
+ background: Color.PRIMARY_HOVER
18
+ },
19
+ off: {
20
+ color: Color.PRIMARY_HOVER,
21
+ background: Color.BRIGHT_LIGHT_HOVER
22
+ }
23
+ },
24
+ muted: {
25
+ on: {
26
+ color: Color.CLEAR,
27
+ background: Color.MAIN
28
+ },
29
+ off: {
30
+ color: Color.MAIN,
31
+ background: Color.SOFT_LIGHT
32
+ }
33
+ }
34
+ };
35
+ const colors = kind => ({
36
+ $isSelected
37
+ }) => {
38
+ const {
39
+ color,
40
+ background
41
+ } = palette[kind][$isSelected ? 'on' : 'off'];
42
+ return `color: ${color}; background: ${background};`;
43
+ };
44
+ const interactive = css(["cursor:pointer;&:hover,&:active{", "}&:active{opacity:0.5;}"], colors('hover'));
45
+ export const PillStyled = styled.button.withConfig({
46
+ displayName: "PillStyled",
47
+ componentId: "sc-e4iqh8-0"
48
+ })(["appearance:none;display:inline-flex;align-items:center;flex-shrink:0;min-height:24px;margin:0;padding:0 8px;border:0;border-radius:", ";font-family:", ";font-size:", ";font-weight:", ";line-height:", ";white-space:nowrap;cursor:default;", " opacity:", ";", " &:disabled{cursor:not-allowed;}&:focus-visible{outline:1px solid ", ";outline-offset:2px;}"], ShapeRadius.CONTROL, FontFamily.MAIN, FontSize.REGULAR, FontWeight.REGULAR, LineHeight.REGULAR, props => colors(props.$isMuted ? 'muted' : 'active')(props), ({
49
+ $isDisabled
50
+ }) => $isDisabled ? 0.5 : 1, ({
51
+ $isMuted
52
+ }) => !$isMuted && interactive, Color.BRIGHT);
@@ -0,0 +1,18 @@
1
+ import type { ButtonHTMLAttributes } from 'react';
2
+ /** Props of {@link Pill} — `<button>` attributes plus the pill state. */
3
+ export type PillProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'disabled' | 'role'> & {
4
+ /** Selected (on) state: filled primary pill, reported as `aria-checked` for `role="radio"`, else `aria-pressed`. */
5
+ isSelected?: boolean;
6
+ /** Disabled: read-only colors at 50% opacity, no interaction. */
7
+ isDisabled?: boolean;
8
+ /** Read-only: muted colors, keeps focus but ignores clicks. */
9
+ isReadOnly?: boolean;
10
+ /** `radio` for a pill inside a radiogroup; a toggle button otherwise. */
11
+ role?: 'radio';
12
+ };
13
+ /** Internal style props of the pill. */
14
+ export type PillStyledProps = {
15
+ $isSelected: boolean;
16
+ $isMuted: boolean;
17
+ $isDisabled: boolean;
18
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { PillSelector } from './PillSelector';
2
+ export { Pill, type PillProps } from './components/Pill';
3
+ export type { PillSelectorProps, PillSelectorRadioProps, PillSelectorCheckboxProps, PillSelectorItem, } from './types';
@@ -0,0 +1,2 @@
1
+ export { PillSelector } from './PillSelector';
2
+ export { Pill } from './components/Pill';
@@ -0,0 +1,6 @@
1
+ export declare const Container: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
2
+ style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
3
+ }> & string;
4
+ export declare const PillRow: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
5
+ style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
6
+ }> & string;
@@ -0,0 +1,9 @@
1
+ import styled from 'styled-components';
2
+ export const Container = styled.div.withConfig({
3
+ displayName: "Container",
4
+ componentId: "sc-1mbz7ub-0"
5
+ })(["display:flex;flex-direction:column;align-items:flex-start;gap:8px;"]);
6
+ export const PillRow = styled.div.withConfig({
7
+ displayName: "PillRow",
8
+ componentId: "sc-1mbz7ub-1"
9
+ })(["display:flex;flex-wrap:wrap;align-items:center;gap:4px;width:100%;"]);
@@ -0,0 +1,53 @@
1
+ import type { ReactNode } from 'react';
2
+ /** One option of a {@link PillSelector}. */
3
+ export type PillSelectorItem = {
4
+ /** Value reported to `onChange`. */
5
+ value: string;
6
+ /** Pill text. */
7
+ label: ReactNode;
8
+ /** Disable this pill only. */
9
+ isDisabled?: boolean;
10
+ };
11
+ /** Accessible name of the group: the visible `title`, or `aria-label` for a bare row. */
12
+ type PillSelectorNameProps = {
13
+ /** Field-box header above the pills; it also names the group. */
14
+ title: ReactNode;
15
+ /** Accessible name; overridden by `title` for screen readers. */
16
+ 'aria-label'?: string;
17
+ } | {
18
+ /** Optional header above the pills. */
19
+ title?: ReactNode;
20
+ /** Accessible name, required when there is no `title`. */
21
+ 'aria-label': string;
22
+ };
23
+ type PillSelectorCommonProps = PillSelectorNameProps & {
24
+ /** Options, rendered in order and wrapped onto new lines when they do not fit. */
25
+ items: PillSelectorItem[];
26
+ /** Disable every pill. */
27
+ isDisabled?: boolean;
28
+ /** Show the selection without letting it change. */
29
+ isReadOnly?: boolean;
30
+ /** Class of the outer wrapper. */
31
+ className?: string;
32
+ };
33
+ /** Radio mode: exactly one pill is selected, a click on the selected one changes nothing. */
34
+ export type PillSelectorRadioProps = PillSelectorCommonProps & {
35
+ /** Selection mode (default `radio`). */
36
+ mode?: 'radio';
37
+ /** Selected value (controlled). */
38
+ value: string | null | undefined;
39
+ /** Fires with the newly selected value. */
40
+ onChange: (value: string) => void;
41
+ };
42
+ /** Checkbox mode: any number of pills is selected, a click toggles one. */
43
+ export type PillSelectorCheckboxProps = PillSelectorCommonProps & {
44
+ /** Selection mode. */
45
+ mode: 'checkbox';
46
+ /** Selected values (controlled). */
47
+ value: string[];
48
+ /** Fires with the next selection; a newly checked value is appended. */
49
+ onChange: (value: string[]) => void;
50
+ };
51
+ /** Props of {@link PillSelector}. */
52
+ export type PillSelectorProps = PillSelectorRadioProps | PillSelectorCheckboxProps;
53
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -3,7 +3,7 @@ import { Color } from '@pushwoosh/kit-constants';
3
3
  import { Vertical } from '@pushwoosh/kit-helpers';
4
4
  import { Text } from '@pushwoosh/kit-typography';
5
5
  import { Lang } from './polyglot';
6
- import { Bubble, Phone, PhoneHeader, Placeholder, Thread } from './styles';
6
+ import { Bubble, Phone, PhoneHeader, Placeholder, SenderName, Thread } from './styles';
7
7
  /** Renders a text message in a phone thread: sender on top, one bubble, segment count below. */
8
8
  export function SmsPreview(props) {
9
9
  const {
@@ -18,8 +18,7 @@ export function SmsPreview(props) {
18
18
  "$alignContent": "start",
19
19
  children: [_jsxs(Phone, {
20
20
  children: [_jsxs(PhoneHeader, {
21
- children: [_jsx(Text, {
22
- "$variant": "h4",
21
+ children: [_jsx(SenderName, {
23
22
  children: senderName
24
23
  }), _jsx(Text, {
25
24
  "$color": Color.LOCKED,
@@ -4,6 +4,9 @@ export declare const Phone: import("styled-components/dist/types").IStyledCompon
4
4
  export declare const PhoneHeader: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
5
5
  style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
6
6
  }> & string;
7
+ export declare const SenderName: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "style"> & {
8
+ style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
9
+ }> & string;
7
10
  export declare const Thread: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
8
11
  style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
9
12
  }> & string;
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { Color, FontSize, ShapeRadius } from '@pushwoosh/kit-constants';
2
+ import { Color, FontFamily, FontSize, FontWeight, LineHeight, ShapeRadius } from '@pushwoosh/kit-constants';
3
3
  export const Phone = styled.div.withConfig({
4
4
  displayName: "Phone",
5
5
  componentId: "sc-1wraspo-0"
@@ -8,15 +8,19 @@ export const PhoneHeader = styled.div.withConfig({
8
8
  displayName: "PhoneHeader",
9
9
  componentId: "sc-1wraspo-1"
10
10
  })(["display:flex;flex-direction:column;gap:2px;padding:12px;border-bottom:1px solid ", ";text-align:center;"], Color.DIVIDER);
11
+ export const SenderName = styled.span.withConfig({
12
+ displayName: "SenderName",
13
+ componentId: "sc-1wraspo-2"
14
+ })(["color:", ";font-family:", ";font-size:", ";font-weight:", ";line-height:", ";"], Color.MAIN, FontFamily.MAIN, FontSize.HEADING4, FontWeight.MEDIUM, LineHeight.HEADING4);
11
15
  export const Thread = styled.div.withConfig({
12
16
  displayName: "Thread",
13
- componentId: "sc-1wraspo-2"
17
+ componentId: "sc-1wraspo-3"
14
18
  })(["display:flex;flex-direction:column;min-height:160px;padding:16px 12px;"]);
15
19
  export const Bubble = styled.div.withConfig({
16
20
  displayName: "Bubble",
17
- componentId: "sc-1wraspo-3"
21
+ componentId: "sc-1wraspo-4"
18
22
  })(["padding:10px 12px;border-radius:16px 16px 16px 4px;background-color:", ";color:", ";font-size:", ";line-height:1.4;white-space:pre-wrap;word-break:break-word;unicode-bidi:plaintext;text-align:start;"], Color.DIVIDER, Color.MAIN, FontSize.REGULAR);
19
23
  export const Placeholder = styled.div.withConfig({
20
24
  displayName: "Placeholder",
21
- componentId: "sc-1wraspo-4"
25
+ componentId: "sc-1wraspo-5"
22
26
  })(["padding:12px;border:1px dashed ", ";border-radius:", ";color:", ";font-size:", ";text-align:center;"], Color.FORM, ShapeRadius.SECTION, Color.LOCKED, FontSize.SMALL);
package/index.d.ts CHANGED
@@ -57,6 +57,7 @@ export { NumberPicker } from './NumberPicker';
57
57
  export { CodeEditor, json as jsonLanguage, html as htmlLanguage } from './CodeEditor';
58
58
  export { EnhancedInput, SearchInput } from './EnhancedInput';
59
59
  export { Chip, type ChipProps, type ChipVariant } from './Chip';
60
+ export { PillSelector, Pill, type PillProps, type PillSelectorProps, type PillSelectorRadioProps, type PillSelectorCheckboxProps, type PillSelectorItem, } from './PillSelector';
60
61
  export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
61
62
  export { SandboxedHtmlFrame, type SandboxedHtmlFrameProps, type IsolatedSandboxedHtmlFrameProps, type InspectableSandboxedHtmlFrameProps, } from './SandboxedHtmlFrame';
62
63
  export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES, EDITABLE_NATIVE_RICH_MEDIA_DISPLAY_TYPES, } from './NativeRichMediaPreview';
package/index.js CHANGED
@@ -51,6 +51,7 @@ export { NumberPicker } from './NumberPicker';
51
51
  export { CodeEditor, json as jsonLanguage, html as htmlLanguage } from './CodeEditor';
52
52
  export { EnhancedInput, SearchInput } from './EnhancedInput';
53
53
  export { Chip } from './Chip';
54
+ export { PillSelector, Pill } from './PillSelector';
54
55
  export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
55
56
  export { SandboxedHtmlFrame } from './SandboxedHtmlFrame';
56
57
  export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES, EDITABLE_NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './NativeRichMediaPreview';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "4.17.1",
3
+ "version": "4.18.0",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -48,7 +48,7 @@
48
48
  "@pushwoosh/kit-constants": "^3.2.1",
49
49
  "@pushwoosh/kit-helpers": "^4.17.2",
50
50
  "@pushwoosh/kit-icons": "^3.0.2",
51
- "@pushwoosh/kit-typography": "^2.1.2",
51
+ "@pushwoosh/kit-typography": "^2.2.0",
52
52
  "@tippyjs/react": "^4.2.6",
53
53
  "@uiw/codemirror-themes": "^4.23.8",
54
54
  "@uiw/react-codemirror": "^4.25.12",