@primer-io/primer-js 0.0.1 → 0.0.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.
@@ -0,0 +1,528 @@
1
+ /**
2
+ * This type can be used to create scoped tags for your components.
3
+ *
4
+ * Usage:
5
+ *
6
+ * ```ts
7
+ * import type { ScopedElements } from "path/to/library/jsx-integration";
8
+ *
9
+ * declare module "my-library" {
10
+ * namespace JSX {
11
+ * interface IntrinsicElements
12
+ * extends ScopedElements<'test-', ''> {}
13
+ * }
14
+ * }
15
+ * ```
16
+ *
17
+ */
18
+ export type ScopedElements<Prefix extends string = "", Suffix extends string = ""> = {
19
+ [Key in keyof CustomElements as `${Prefix}${Key}${Suffix}`]: CustomElements[Key];
20
+ };
21
+
22
+ type BaseProps = {
23
+ /** Content added between the opening and closing tags of the element */
24
+ children?: any;
25
+ /** Used for declaratively styling one or more elements using CSS (Cascading Stylesheets) */
26
+ class?: string;
27
+ /** Used for declaratively styling one or more elements using CSS (Cascading Stylesheets) */
28
+ className?: string;
29
+ /** Takes an object where the key is the class name(s) and the value is a boolean expression. When true, the class is applied, and when false, it is removed. */
30
+ classList?: Record<string, boolean | undefined>;
31
+ /** Specifies the text direction of the element. */
32
+ dir?: "ltr" | "rtl";
33
+ /** Contains a space-separated list of the part names of the element that should be exposed on the host element. */
34
+ exportparts?: string;
35
+ /** For <label> and <output>, lets you associate the label with some control. */
36
+ htmlFor?: string;
37
+ /** Specifies whether the element should be hidden. */
38
+ hidden?: boolean | string;
39
+ /** A unique identifier for the element. */
40
+ id?: string;
41
+ /** Keys tell React which array item each component corresponds to */
42
+ key?: string | number;
43
+ /** Specifies the language of the element. */
44
+ lang?: string;
45
+ /** Contains a space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the ::part pseudo-element. */
46
+ part?: string;
47
+ /** Use the ref attribute with a variable to assign a DOM element to the variable once the element is rendered. */
48
+ ref?: unknown | ((e: unknown) => void);
49
+ /** Adds a reference for a custom element slot */
50
+ slot?: string;
51
+ /** Prop for setting inline styles */
52
+ style?: Record<string, string | number>;
53
+ /** Overrides the default Tab button behavior. Avoid using values other than -1 and 0. */
54
+ tabIndex?: number;
55
+ /** Specifies the tooltip text for the element. */
56
+ title?: string;
57
+ /** Passing 'no' excludes the element content from being translated. */
58
+ translate?: "yes" | "no";
59
+ };
60
+
61
+ type BaseEvents = {};
62
+
63
+ export type PrimerCheckoutComponentProps = {
64
+ /** */
65
+ "custom-styles"?: string;
66
+ /** */
67
+ "client-token"?: string;
68
+ /** */
69
+ options?: PrimerCheckoutOptions;
70
+ /** */
71
+ "disable-loader"?: boolean;
72
+ /** */
73
+ defaultSlot?: HTMLSlotElement;
74
+ /** */
75
+ locale?: LocaleCode | undefined;
76
+ /** */
77
+ sdkContextController?: SDKContextController;
78
+ /** */
79
+ sdkStateController?: SdkStateController;
80
+ /** */
81
+ primerEventsController?: PrimerEventsController;
82
+ /** */
83
+ styleProcessingController?: StyleProcessingController;
84
+ };
85
+
86
+ export type ButtonComponentProps = {
87
+ /** */
88
+ variant?: "primary" | "secondary" | "tertiary";
89
+ /** */
90
+ disabled?: boolean;
91
+ /** */
92
+ buttonType?: "button" | "submit" | "reset";
93
+ };
94
+
95
+ export type PrimerCheckoutStateComponentProps = {
96
+ /** */
97
+ type?: "complete" | "failure";
98
+ /** */
99
+ description?: string | undefined;
100
+ };
101
+
102
+ export type PrimerIconComponentProps = {
103
+ /** */
104
+ color?: string;
105
+ /** */
106
+ size?: "lg" | "sm";
107
+ /** The name of the icon to draw - available names can be found under library.ts file */
108
+ name?: IconName | undefined;
109
+ };
110
+
111
+ export type InputComponentProps = {
112
+ /** */
113
+ value?: string;
114
+ /** */
115
+ placeholder?: string;
116
+ /** */
117
+ disabled?: boolean;
118
+ /** */
119
+ name?: string;
120
+ /** */
121
+ type?: InputType;
122
+ /** */
123
+ required?: boolean;
124
+ /** */
125
+ readonly?: boolean;
126
+ /** */
127
+ pattern?: string;
128
+ /** */
129
+ minlength?: number | undefined;
130
+ /** */
131
+ maxlength?: number | undefined;
132
+ /** */
133
+ min?: string;
134
+ /** */
135
+ max?: string;
136
+ /** */
137
+ step?: string;
138
+ /** */
139
+ autocomplete?: string;
140
+ /** */
141
+ id?: string;
142
+ /** Get the validity state of the input element */
143
+ validity?: ValidityState;
144
+ /** Get the validation message of the input element */
145
+ validationMessage?: string;
146
+ /** Fired when the input receives focus */
147
+ onfocus?: (e: CustomEvent<FocusEvent>) => void;
148
+ /** Fired when the input loses focus */
149
+ onblur?: (e: CustomEvent<FocusEvent>) => void;
150
+ /** Fired when the input fails validation */
151
+ oninvalid?: (e: CustomEvent<Event>) => void;
152
+ /** Fired when the input value changes */
153
+ oninput?: (e: CustomEvent<never>) => void;
154
+ /** Fired when the input value is committed */
155
+ onchange?: (e: CustomEvent<never>) => void;
156
+ };
157
+
158
+ export type InputErrorComponentProps = {
159
+ /** ID of the form control this error message is associated with */
160
+ for?: string;
161
+ /** Whether the error is currently active/visible */
162
+ active?: boolean;
163
+ };
164
+
165
+ export type InputLabelComponentProps = {
166
+ /** ID of the form control this label is associated with */
167
+ for?: string;
168
+ /** Whether the label should appear disabled */
169
+ disabled?: boolean;
170
+ };
171
+
172
+ export type InputWrapperComponentProps = {
173
+ /** */
174
+ focusWithin?: boolean;
175
+ /** */
176
+ "has-error"?: boolean;
177
+
178
+ /** */
179
+ "onwrapper-click"?: (e: CustomEvent<CustomEvent>) => void;
180
+ };
181
+
182
+ export type SpinnerComponentProps = {
183
+ /** Color of the spinner
184
+ Defaults to the design system loader color */
185
+ color?: string;
186
+ /** Size of the spinner
187
+ Available values: 'small', 'medium', 'large' or a custom number as string */
188
+ size?: SpinnerSize | string;
189
+ /** Whether to use compact mode (minimal margins)
190
+ Useful when embedding in inputs */
191
+ compact?: boolean;
192
+ };
193
+
194
+ export type CardFormComponentProps = {
195
+ /** Payment managers injected from context */
196
+ paymentManagers?: InitializedManagersMap;
197
+ };
198
+
199
+ export type NativePaymentComponentProps = {
200
+ /** */
201
+ paymentMethod?: InitializedPaymentMethod | undefined;
202
+ /** */
203
+ paymentManagers?: InitializedManagersMap;
204
+ };
205
+
206
+ export type PaymentMethodComponentProps = {
207
+ /** */
208
+ type?: PaymentMethodType | undefined;
209
+ /** */
210
+ paymentMethods?: PaymentsObject | null;
211
+ };
212
+
213
+ export type PrimerCheckoutCompleteComponentProps = {};
214
+
215
+ export type PrimerCheckoutFailureComponentProps = {
216
+ /** */
217
+ sdkState?: HeadlessSDKState | undefined;
218
+ };
219
+
220
+ export type PrimerMainComponentProps = {
221
+ /** */
222
+ paymentMethods?: PaymentsObject | null;
223
+ /** */
224
+ sdkState?: SdkStateContext | undefined;
225
+ };
226
+
227
+ export type RedirectPaymentComponentProps = {
228
+ /** */
229
+ paymentMethod?: InitializedPaymentMethod | undefined;
230
+ /** */
231
+ paymentManagers?: InitializedManagersMap;
232
+ /** */
233
+ sdkState?: SdkStateContext | undefined;
234
+ };
235
+
236
+ export type CardFormSubmitComponentProps = {
237
+ /** The button text to display.
238
+ Falls back to localized default if not explicitly set. */
239
+ buttonText?: string;
240
+ /** The button variant to use. */
241
+ variant?: string;
242
+ /** Whether the button is disabled. */
243
+ disabled?: boolean;
244
+ };
245
+
246
+ export type CardNetworkSelectorComponentProps = {
247
+ /** Card networks context from provider */
248
+ cardNetworks?: CardNetworksContext | null;
249
+ /** Dispatched when a network is selected with the network name as detail */
250
+ "onnetwork-selected"?: (e: CustomEvent<CustomEvent>) => void;
251
+ };
252
+
253
+ export type InputCardExpiryComponentProps = {
254
+ /** The input label text.
255
+ Falls back to localized default if not explicitly set. */
256
+ label?: string;
257
+ /** The input placeholder text.
258
+ Falls back to localized default if not explicitly set.
259
+ When explicitly set to empty string, no placeholder will be displayed. */
260
+ placeholder?: string;
261
+ /** The input aria-label attribute.
262
+ Falls back to localized default if not explicitly set. */
263
+ "aria-label"?: string;
264
+ /** */
265
+ cardFormContext?: CardFormContext | null;
266
+ };
267
+
268
+ export type InputCardHolderNameComponentProps = {
269
+ /** The input label text.
270
+ Falls back to localized default if not explicitly set. */
271
+ label?: string;
272
+ /** The input placeholder text.
273
+ Falls back to localized default if not explicitly set.
274
+ When explicitly set to empty string, no placeholder will be displayed. */
275
+ placeholder?: string;
276
+ /** The input aria-label attribute.
277
+ Falls back to localized default if not explicitly set. */
278
+ "aria-label"?: string;
279
+ /** */
280
+ cardFormContext?: CardFormContext | null;
281
+ };
282
+
283
+ export type InputCardNumberComponentProps = {
284
+ /** The input label text.
285
+ Falls back to localized default if not explicitly set. */
286
+ label?: string;
287
+ /** The input placeholder text.
288
+ Falls back to localized default if not explicitly set.
289
+ When explicitly set to empty string, no placeholder will be displayed. */
290
+ placeholder?: string;
291
+ /** The input aria-label attribute.
292
+ Falls back to localized default if not explicitly set. */
293
+ "aria-label"?: string;
294
+ /** */
295
+ cardFormContext?: CardFormContext | null;
296
+ };
297
+
298
+ export type InputCvvComponentProps = {
299
+ /** The input label text.
300
+ Falls back to localized default if not explicitly set. */
301
+ label?: string;
302
+ /** The input placeholder text.
303
+ Falls back to localized default if not explicitly set.
304
+ When explicitly set to empty string, no placeholder will be displayed. */
305
+ placeholder?: string;
306
+ /** The input aria-label attribute.
307
+ Falls back to localized default if not explicitly set. */
308
+ "aria-label"?: string;
309
+ /** */
310
+ cardFormContext?: CardFormContext | null;
311
+ };
312
+
313
+ export type CustomElements = {
314
+ /**
315
+ *
316
+ * ---
317
+ *
318
+ */
319
+ "primer-checkout": Partial<PrimerCheckoutComponentProps & BaseProps & BaseEvents>;
320
+
321
+ /**
322
+ *
323
+ * ---
324
+ *
325
+ */
326
+ "primer-button": Partial<ButtonComponentProps & BaseProps & BaseEvents>;
327
+
328
+ /**
329
+ *
330
+ * ---
331
+ *
332
+ */
333
+ "primer-checkout-state": Partial<PrimerCheckoutStateComponentProps & BaseProps & BaseEvents>;
334
+
335
+ /**
336
+ *
337
+ * ---
338
+ *
339
+ */
340
+ "primer-icon": Partial<PrimerIconComponentProps & BaseProps & BaseEvents>;
341
+
342
+ /**
343
+ * A fully type-safe input component that wraps the native HTML input element
344
+ * while providing additional functionality and styling.
345
+ * ---
346
+ *
347
+ *
348
+ * ### **Events:**
349
+ * - **focus** - Fired when the input receives focus
350
+ * - **blur** - Fired when the input loses focus
351
+ * - **invalid** - Fired when the input fails validation
352
+ * - **input** - Fired when the input value changes
353
+ * - **change** - Fired when the input value is committed
354
+ *
355
+ * ### **Methods:**
356
+ * - **focus(options: _FocusOptions_): _void_** - Focus the input element
357
+ * - **blur(): _void_** - Remove focus from the input element
358
+ * - **select(): _void_** - Select all text in the input element
359
+ * - **setSelectionRange(start: _number_, end: _number_, direction: _'forward' | 'backward' | 'none'_): _void_** - Set the selection range of the input element
360
+ * - **checkValidity(): _boolean_** - Check if the input element is valid
361
+ * - **reportValidity(): _boolean_** - Report the validity of the input element
362
+ * - **addEventListener(type: _K_, listener: _(ev: InputEventMap[K]) => void_, options: _boolean | AddEventListenerOptions_): _void_** - Type safe event dispatcher - allows consumers to use proper types
363
+ * when listening to events from this component
364
+ * - **removeEventListener(type: _K_, listener: _(ev: InputEventMap[K]) => void_, options: _boolean | EventListenerOptions_): _void_** - Type safe event dispatcher removal
365
+ *
366
+ * ### **CSS Parts:**
367
+ * - **input** - The native input element
368
+ */
369
+ "primer-input": Partial<InputComponentProps & BaseProps & BaseEvents>;
370
+
371
+ /**
372
+ * Input error component for displaying form validation messages
373
+ * ---
374
+ *
375
+ *
376
+ * ### **Slots:**
377
+ * - _default_ - Default slot for error message content
378
+ */
379
+ "primer-input-error": Partial<InputErrorComponentProps & BaseProps & BaseEvents>;
380
+
381
+ /**
382
+ * Input label component for form elements
383
+ * ---
384
+ *
385
+ *
386
+ * ### **Slots:**
387
+ * - _default_ - Default slot for label text content
388
+ */
389
+ "primer-input-label": Partial<InputLabelComponentProps & BaseProps & BaseEvents>;
390
+
391
+ /**
392
+ * A wrapper component for input elements that handles focus styling and interactions.
393
+ * Provides an improved user experience by making the entire wrapper clickable to focus the inner input.
394
+ *
395
+ * Features:
396
+ * - Automatically focuses primer-input elements when wrapper is clicked
397
+ * - Dispatches wrapper-click events for iframe-based hosted inputs
398
+ * - Sets proper cursor styling to indicate text input functionality
399
+ * ---
400
+ *
401
+ *
402
+ * ### **Events:**
403
+ * - **wrapper-click**
404
+ */
405
+ "primer-input-wrapper": Partial<InputWrapperComponentProps & BaseProps & BaseEvents>;
406
+
407
+ /**
408
+ * Spinner component with configurable size and color
409
+ * Adapted to work both standalone and within input components
410
+ * ---
411
+ *
412
+ */
413
+ "primer-spinner": Partial<SpinnerComponentProps & BaseProps & BaseEvents>;
414
+
415
+ /**
416
+ * CardFormComponent serves as a container for card input components.
417
+ * It handles form submission, validation, and provides context to child components.
418
+ * ---
419
+ *
420
+ */
421
+ "primer-card-form": Partial<CardFormComponentProps & BaseProps & BaseEvents>;
422
+
423
+ /**
424
+ * Component for rendering native payment buttons (Apple Pay, Google Pay, PayPal)
425
+ * with proper height calculations based on design system variables.
426
+ * ---
427
+ *
428
+ */
429
+ "primer-native-payment": Partial<NativePaymentComponentProps & BaseProps & BaseEvents>;
430
+
431
+ /**
432
+ *
433
+ * ---
434
+ *
435
+ */
436
+ "primer-payment-method": Partial<PaymentMethodComponentProps & BaseProps & BaseEvents>;
437
+
438
+ /**
439
+ *
440
+ * ---
441
+ *
442
+ */
443
+ "primer-checkout-complete": Partial<PrimerCheckoutCompleteComponentProps & BaseProps & BaseEvents>;
444
+
445
+ /**
446
+ *
447
+ * ---
448
+ *
449
+ */
450
+ "primer-checkout-failure": Partial<PrimerCheckoutFailureComponentProps & BaseProps & BaseEvents>;
451
+
452
+ /**
453
+ *
454
+ * ---
455
+ *
456
+ */
457
+ "primer-main": Partial<PrimerMainComponentProps & BaseProps & BaseEvents>;
458
+
459
+ /**
460
+ *
461
+ * ---
462
+ *
463
+ */
464
+ "primer-redirect-payment": Partial<RedirectPaymentComponentProps & BaseProps & BaseEvents>;
465
+
466
+ /**
467
+ * A form submit button component for card forms.
468
+ * Provides a consistent submit button with translation support.
469
+ * ---
470
+ *
471
+ */
472
+ "primer-card-form-submit": Partial<CardFormSubmitComponentProps & BaseProps & BaseEvents>;
473
+
474
+ /**
475
+ * Component for displaying and selecting card networks
476
+ * Uses context directly rather than properties
477
+ * ---
478
+ *
479
+ *
480
+ * ### **Events:**
481
+ * - **network-selected** - Dispatched when a network is selected with the network name as detail
482
+ */
483
+ "primer-card-network-selector": Partial<CardNetworkSelectorComponentProps & BaseProps & BaseEvents>;
484
+
485
+ /**
486
+ *
487
+ * ---
488
+ *
489
+ *
490
+ * ### **Methods:**
491
+ *
492
+ *
493
+ */
494
+ "primer-input-card-expiry": Partial<InputCardExpiryComponentProps & BaseProps & BaseEvents>;
495
+
496
+ /**
497
+ *
498
+ * ---
499
+ *
500
+ *
501
+ * ### **Methods:**
502
+ *
503
+ *
504
+ */
505
+ "primer-input-card-holder-name": Partial<InputCardHolderNameComponentProps & BaseProps & BaseEvents>;
506
+
507
+ /**
508
+ * Card number input component with dynamic card network detection and selection
509
+ * ---
510
+ *
511
+ *
512
+ * ### **Methods:**
513
+ *
514
+ *
515
+ */
516
+ "primer-input-card-number": Partial<InputCardNumberComponentProps & BaseProps & BaseEvents>;
517
+
518
+ /**
519
+ *
520
+ * ---
521
+ *
522
+ *
523
+ * ### **Methods:**
524
+ *
525
+ *
526
+ */
527
+ "primer-input-cvv": Partial<InputCvvComponentProps & BaseProps & BaseEvents>;
528
+ };