@mobilestock-native/segmented-control 0.0.0-stage → 0.1.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.
package/index.d.ts ADDED
@@ -0,0 +1,90 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { IconName } from '@mobilestock-native/icons';
3
+
4
+ type SegmentedControlSize = 'SM' | 'MD';
5
+ interface SegmentedControlOptionBase<ValueGeneric extends string> {
6
+ /**
7
+ * @description Unique value of the option, delivered to `onChange` when it is selected.
8
+ * Default: required
9
+ * @example value="LIST"
10
+ */
11
+ value: ValueGeneric;
12
+ /**
13
+ * @description Disables the option: it is dimmed, ignores touches and is skipped by the keyboard arrows.
14
+ * Default: false
15
+ * @example disabled={true}
16
+ */
17
+ disabled?: boolean;
18
+ }
19
+ interface SegmentedControlOptionWithLabel<ValueGeneric extends string> extends SegmentedControlOptionBase<ValueGeneric> {
20
+ /**
21
+ * @description Text displayed in the option. It is also the accessibility label when `accessibilityLabel` is omitted.
22
+ * Default: required (unless the option has an `icon` and an `accessibilityLabel`)
23
+ * @example label="Lista"
24
+ */
25
+ label: string;
26
+ /**
27
+ * @description Icon displayed before the label.
28
+ * Default: undefined (no icon)
29
+ * @example icon="ListBullet"
30
+ */
31
+ icon?: IconName;
32
+ /**
33
+ * @description Accessibility label read by screen readers instead of the `label`.
34
+ * Default: undefined (uses `label`)
35
+ * @example accessibilityLabel="Exibir em lista"
36
+ */
37
+ accessibilityLabel?: string;
38
+ }
39
+ interface SegmentedControlOptionIconOnly<ValueGeneric extends string> extends SegmentedControlOptionBase<ValueGeneric> {
40
+ label?: undefined;
41
+ /**
42
+ * @description Icon displayed as the only content of the option.
43
+ * Default: required when there is no `label`
44
+ * @example icon="Grid"
45
+ */
46
+ icon: IconName;
47
+ /**
48
+ * @description Accessibility label read by screen readers. Required because the option has no visible text.
49
+ * Default: required when there is no `label`
50
+ * @example accessibilityLabel="Grade"
51
+ */
52
+ accessibilityLabel: string;
53
+ }
54
+ type SegmentedControlOption<ValueGeneric extends string = string> = SegmentedControlOptionWithLabel<ValueGeneric> | SegmentedControlOptionIconOnly<ValueGeneric>;
55
+ interface SegmentedControlProps<ValueGeneric extends string = string> {
56
+ /**
57
+ * @description Options displayed in the track, in order. An option without `label` must have `icon` and `accessibilityLabel`.
58
+ * Default: required
59
+ * @example options={[{ value: 'LIST', label: 'Lista', icon: 'ListBullet' }, { value: 'GRID', label: 'Grade', icon: 'Grid' }]}
60
+ */
61
+ options: SegmentedControlOption<ValueGeneric>[];
62
+ /**
63
+ * @description Value of the selected option (controlled component).
64
+ * Default: required
65
+ * @example value="LIST"
66
+ */
67
+ value: ValueGeneric;
68
+ /**
69
+ * @description Called with the value of the option the user selected by touch, click or keyboard arrows.
70
+ * Default: required
71
+ * @example onChange={value => setView(value)}
72
+ */
73
+ onChange(value: ValueGeneric): void;
74
+ /**
75
+ * @description Size of the options (padding, font and icon).
76
+ * Default: 'MD'
77
+ * @example size="SM"
78
+ */
79
+ size?: SegmentedControlSize;
80
+ /**
81
+ * @description Test identifier of the track. Each option receives `${testID}-option-${value}`.
82
+ * Default: 'segmented-control'
83
+ * @example testID="view-mode"
84
+ */
85
+ testID?: string;
86
+ }
87
+
88
+ declare function SegmentedControl<ValueGeneric extends string>({ options, value, onChange, size, testID }: SegmentedControlProps<ValueGeneric>): react_jsx_runtime.JSX.Element;
89
+
90
+ export { SegmentedControl, type SegmentedControlOption, type SegmentedControlProps, type SegmentedControlSize };
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";var T=Object.create;var p=Object.defineProperty,h=Object.defineProperties,L=Object.getOwnPropertyDescriptor,M=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertyNames,S=Object.getOwnPropertySymbols,A=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var x=(e,o,n)=>o in e?p(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,y=(e,o)=>{for(var n in o||(o={}))C.call(o,n)&&x(e,n,o[n]);if(S)for(var n of S(o))K.call(o,n)&&x(e,n,o[n]);return e},O=(e,o)=>h(e,M(o));var Y=(e,o)=>{for(var n in o)p(e,n,{get:o[n],enumerable:!0})},w=(e,o,n,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of N(o))!C.call(e,r)&&r!==n&&p(e,r,{get:()=>o[r],enumerable:!(t=L(o,r))||t.enumerable});return e};var E=(e,o,n)=>(n=e!=null?T(A(e)):{},w(o||!e||!e.__esModule?p(n,"default",{value:e,enumerable:!0}):n,e)),B=e=>w(p({},"__esModule",{value:!0}),e);var U={};Y(U,{SegmentedControl:()=>_});module.exports=B(U);var v=require("react"),G=require("react-native"),k=E(require("styled-components/native")),z=require("@mobilestock-native/container");var I={ArrowRight:1,ArrowLeft:-1};function R(e,o,n){let t=e.length,r=e.findIndex(i=>i.value===o);for(let i=1;i<t;i++){let a=((r+n*i)%t+t)%t,d=e[a];if(!d.disabled)return d.value}return null}var u=require("react-native"),f=E(require("styled-components/native")),V=require("@mobilestock-native/container"),D=require("@mobilestock-native/icons"),$=require("@mobilestock-native/typography"),c=require("react/jsx-runtime"),X={SM:"2XS",MD:"XS"},Z={SM:"XS",MD:"SM"};function P({option:e,selected:o,size:n,testID:t,pressableRef:r,onSelect:i}){var s;let a=!!e.disabled,d=u.Platform.OS==="web"?o?0:-1:void 0;function l(){o||i(e.value)}return(0,c.jsx)(H,{ref:r,testID:t,accessibilityRole:"radio",accessibilityState:{selected:o,checked:o,disabled:a},accessibilityLabel:(s=e.accessibilityLabel)!=null?s:e.label,disabled:a,tabIndex:d,onPress:l,$selected:o,$disabled:a,$size:n,children:(0,c.jsxs)(V.Container.Horizontal,{gap:"2XS",align:"CENTER_CENTER",opacity:o?void 0:"0.6",children:[e.icon&&(0,c.jsx)(D.Icon,{name:e.icon,size:X[n]}),e.label&&(0,c.jsx)($.Typography,{size:Z[n],weight:o?"SEMIBOLD":"REGULAR",children:e.label})]})})}var H=(0,f.default)(u.Pressable)`
2
+ padding: ${({theme:e,$size:o})=>`${e.spacing["2xs"]} ${o==="SM"?e.spacing.xs:e.spacing.sm}`};
3
+ border-radius: ${({theme:e})=>e.borderRadius.default};
4
+ opacity: ${({$disabled:e})=>e?.4:1};
5
+ ${({$selected:e,theme:o})=>e&&f.css`
6
+ background-color: ${o.colors.segmentedControl.selected};
7
+ shadow-color: ${o.colors.segmentedControl.shadow};
8
+ shadow-offset: 0px 1px;
9
+ shadow-opacity: 1;
10
+ shadow-radius: 3px;
11
+ elevation: 1;
12
+ `}
13
+ `;var g=require("react/jsx-runtime");function _({options:e,value:o,onChange:n,size:t="MD",testID:r="segmented-control"}){let i=(0,v.useRef)({}),a=G.Platform.OS==="web"?{onKeyDown:d}:{};function d(l){var b;let s=I[l.key];if(!s)return;l.preventDefault();let m=R(e,o,s);m!==null&&(n(m),(b=i.current[m])==null||b.focus())}return(0,g.jsx)(F,O(y({testID:r,accessibilityRole:"radiogroup",gap:"2XS",borderRadius:"DEFAULT"},a),{children:e.map(l=>(0,g.jsx)(P,{option:l,selected:l.value===o,size:t,testID:`${r}-option-${l.value}`,pressableRef:s=>{i.current[l.value]=s},onSelect:n},l.value))}))}var F=(0,k.default)(z.Container.Horizontal)`
14
+ align-self: flex-start;
15
+ padding: ${({theme:e})=>e.spacing["2xs"]};
16
+ background-color: ${({theme:e})=>e.colors.segmentedControl.track};
17
+ `;0&&(module.exports={SegmentedControl});
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "@mobilestock-native/segmented-control",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "main": "index.js",
5
+ "dependencies": {
6
+ "@mobilestock-native/container": "^1.4.0",
7
+ "@mobilestock-native/icons": "^0.8.0",
8
+ "@mobilestock-native/typography": "^0.1.3"
9
+ },
10
+ "peerDependencies": {
11
+ "react": "18.2.0",
12
+ "react-native": "0.74.5",
13
+ "styled-components": "^6.1.8"
14
+ }
6
15
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.