diff --git a/.cursor/rules/svelte-migration.mdc b/.cursor/rules/svelte-migration.mdc new file mode 100644 index 00000000000..5c5574fb2d3 --- /dev/null +++ b/.cursor/rules/svelte-migration.mdc @@ -0,0 +1,64 @@ +--- +description: +globs: +alwaysApply: false +--- + +You work in design system of Razorpay and you are migrating existing components of Blade from React to Svelte. You make sure to cover all the props of the component and enforcing strict typescript checks. + +- You refer to existing components for expected props and HTML structure +- You understand the common props that we normally use, compound component structure that we normally use and follow WISIWYG (What You See is What You Get) Philosophy. +- Before writing the component refer to the corresponding React component written in - `packages/blade/src/components` folder +- Wherever you are unsure about some practice, just ask for confirmation +- Before writing the component, you discuss the approach on how you are writing the component and only write post confirmation +- The API structure of the components should clean and easier to understand and integrate +- Some component might be using another component like Link or Button component uses Icon or BaseText. Wherever this case is there confirm whether to make a migration for that or not for the imported components like Icons +Don't use createEventDispatcher for event handlers like on:click etc. Instead use a prop based mechanism expect and pass a prop +- Any utility function like - `packages/blade/src/utils/makeBorderSize/index.ts` should be placed in blade core util directory - `packages/blade-core/src/utils` and not within the blade-svelte directory. +- Whenever any utility import is encountered check in - `packages/blade-core/src/utils` directory, if the util file is not present or same function is not present ask for a confirmation before adding. + +## Blade Component Svelte Guidelines +### Key Examples for references +- Study the props of the React component which you are trying to migrate to Svelte. Props should remain consistent throughout Svelte and React components. + +## Directory Structure + +Components should be created in the following structure: + +``` +packages/ +└── blade-svelte/ + └── src/ + └── components/ + ├── Button/ + │ ├── Button.svelte + │ └── button.css + ├── Link/ + │ ├── BaseLink/ + │ │ ├── BaseLink.svelte + │ │ └── baseLink.css + │ └── Link.svelte + └── ... (other components) +``` + +### Naming Conventions +- Component directories: `PascalCase` (e.g., `Button/`, `Link/`) +- Component files: `PascalCase.svelte` (e.g., `Button.svelte`, `BaseLink.svelte`) +- CSS files: `camelCase.css` (e.g., `button.css`, `baseLink.css`) +- For nested/base components, create a subdirectory with the component name (e.g., `Link/BaseLink/`) + +## Import Guidelines +- Components in svelte directory have all the blade tokens listed in `packages/blade-svelte/src/theme/theme.css` +- There is an existing example at `packages/blade-svelte/src/components/Button/` which you can refer to for any example +- You can use common function from `packages/blade-core` if needed. However do confirm before you implement + +## Testing Guidelines +Add the component in packages/blade-svelte/src/App.svelte as well which will be a testing playground for testing whether component is behaving as expected or not + +## Accessibility and CSS Patterns + +#### Implementation Guidelines + +- Always set the `disabled` attribute on the element when the component is disabled +- Use `[disabled]` attribute selector in CSS instead of adding/removing classes +- This pattern applies to buttons, links, and other interactive elements that support disabled states \ No newline at end of file diff --git a/packages/blade-core/package.json b/packages/blade-core/package.json index cbc441b05f3..d23a98846d1 100644 --- a/packages/blade-core/package.json +++ b/packages/blade-core/package.json @@ -22,10 +22,12 @@ "typecheck:web": "tsc --noEmit --project tsconfig-typecheck.web.json", "typecheck:native": "tsc --noEmit --project tsconfig-typecheck.native.json", "build": "yarn build:generate-types && yarn build:rollup", + "build:watch": "yarn build:generate-types && yarn build:rollup:watch", "build:generate-types": "yarn build:generate-types:web && yarn build:generate-types:native", "build:generate-types:web": "tsc --project tsconfig-generate-types.web.json", "build:generate-types:native": "tsc --project tsconfig-generate-types.native.json", "build:rollup": "rollup --config rollup.config.mjs", + "build:rollup:watch": "rollup --config rollup.config.mjs --watch", "build:rollup:web": "FRAMEWORK=REACT rollup --config rollup.config.mjs", "build:rollup:native": "FRAMEWORK=REACT_NATIVE rollup --config rollup.config.mjs", "test": "echo 'No tests configured yet'" @@ -69,11 +71,15 @@ "exports": { "./tokens": { "types": "./dist/types/tokens/index.d.ts", + "development": "./dist/lib/web/development/tokens/index.js", + "production": "./dist/lib/web/production/tokens/index.js", "default": "./dist/lib/web/production/tokens/index.js" }, "./tokens/theme.css": "./dist/lib/web/production/tokens/theme.css", "./utils": { "types": "./dist/types/utils/index.d.ts", + "development": "./dist/lib/web/development/utils/index.js", + "production": "./dist/lib/web/production/utils/index.js", "default": "./dist/lib/web/production/utils/index.js" } } diff --git a/packages/blade-core/src/utils/index.ts b/packages/blade-core/src/utils/index.ts index 5a79ae05e98..607d66c9d7a 100644 --- a/packages/blade-core/src/utils/index.ts +++ b/packages/blade-core/src/utils/index.ts @@ -14,6 +14,9 @@ export * from './lodashButBetter/throttle'; export * from './hasSameObjectStructure'; export * from './isPartialMatchObjectKeys'; export * from './logger'; +export * from './makeAccessible'; +export * from './makeAnalyticsAttribute'; +export * from './metaAttribute'; export * from './makeBezier'; export * from './platform'; export * from './types'; diff --git a/packages/blade-core/src/utils/makeAccessible/accessibilityMap.ts b/packages/blade-core/src/utils/makeAccessible/accessibilityMap.ts new file mode 100644 index 00000000000..3c64d89b818 --- /dev/null +++ b/packages/blade-core/src/utils/makeAccessible/accessibilityMap.ts @@ -0,0 +1,63 @@ +import type { AccessibilityMap } from './types'; + +export const accessibilityValue = { + valueMax: 'aria-valuemax', + valueMin: 'aria-valuemin', + valueNow: 'aria-valuenow', + valueText: 'aria-valuetext', +}; + +export const accessibilityState = { + selected: 'aria-selected', + disabled: 'aria-disabled', + expanded: 'aria-expanded', + busy: 'aria-busy', + checked: 'aria-checked', +}; + +// TODO: +// accessibilityViewIsModal +export const accessibilityMap: AccessibilityMap = { + ...accessibilityState, + ...accessibilityValue, + activeDescendant: 'aria-activedescendant', + atomic: 'aria-atomic', + autoComplete: 'aria-autocomplete', + colCount: 'aria-colcount', + colIndex: 'aria-colindex', + colSpan: 'aria-colspan', + controls: 'aria-controls', + describedBy: 'aria-describedby', + details: 'aria-details', + errorMessage: 'aria-errormessage', + flowTo: 'aria-flowto', + hasPopup: 'aria-haspopup', + hidden: 'aria-hidden', + invalid: 'aria-invalid', + keyShortcuts: 'aria-keyshortcuts', + label: 'aria-label', + labelledBy: 'aria-labelledby', + liveRegion: 'aria-live', + modal: 'aria-modal', + multiline: 'aria-multiline', + multiSelectable: 'aria-multiselectable', + orientation: 'aria-orientation', + owns: 'aria-owns', + placeholder: 'aria-placeholder', + posInSet: 'aria-posinset', + pressed: 'aria-pressed', + readOnly: 'aria-readonly', + required: 'aria-required', + role: 'role', + roleDescription: 'aria-roledescription', + rowCount: 'aria-rowcount', + rowIndex: 'aria-rowindex', + rowSpan: 'aria-rowspan', + setSize: 'aria-setsize', + sort: 'aria-sort', + current: 'aria-current', + dropEffect: 'aria-dropeffect', + grabbed: 'aria-grabbed', + level: 'aria-level', + relevant: 'aria-relevant', +}; diff --git a/packages/blade-core/src/utils/makeAccessible/index.ts b/packages/blade-core/src/utils/makeAccessible/index.ts new file mode 100644 index 00000000000..562e9ff3b99 --- /dev/null +++ b/packages/blade-core/src/utils/makeAccessible/index.ts @@ -0,0 +1,2 @@ +export * from './makeAccessible'; +export * from './types'; diff --git a/packages/blade-core/src/utils/makeAccessible/makeAccessible.ts b/packages/blade-core/src/utils/makeAccessible/makeAccessible.ts new file mode 100644 index 00000000000..3db7f9a2d5c --- /dev/null +++ b/packages/blade-core/src/utils/makeAccessible/makeAccessible.ts @@ -0,0 +1,27 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { accessibilityMap } from './accessibilityMap'; +import type { AccessibilityMap, AccessibilityProps } from './types'; +import { logger } from '~utils/logger'; + +export const makeAccessible = (props: Partial): Record => { + const newProps: Record = {}; + + // eslint-disable-next-line guard-for-in + for (const key in props) { + const propKey = key as keyof AccessibilityMap; + const propValue = props[propKey]; + const accessibilityAttribute = accessibilityMap[propKey]; + + if (accessibilityAttribute) { + newProps[accessibilityAttribute] = propValue; + } else if (__DEV__) { + logger({ + message: `No mapping found for ${propKey}. Make sure you have entered valid key`, + moduleName: 'makeAccessible', + type: 'warn', + }); + } + } + + return newProps; +}; diff --git a/packages/blade-core/src/utils/makeAccessible/types.ts b/packages/blade-core/src/utils/makeAccessible/types.ts new file mode 100644 index 00000000000..f551e465dd6 --- /dev/null +++ b/packages/blade-core/src/utils/makeAccessible/types.ts @@ -0,0 +1,314 @@ +import type { AccessibilityRole } from 'react-native'; + +// All the WAI-ARIA 1.1 role attribute values from https://www.w3.org/TR/wai-aria-1.1/#role_definitions +export type AriaRoles = + | Exclude + | 'alert' + | 'alertdialog' + | 'application' + | 'article' + | 'banner' + | 'button' + | 'cell' + | 'checkbox' + | 'columnheader' + | 'combobox' + | 'complementary' + | 'contentinfo' + | 'definition' + | 'dialog' + | 'directory' + | 'document' + | 'feed' + | 'figure' + | 'form' + | 'grid' + | 'gridcell' + | 'group' + | 'heading' + | 'img' + | 'link' + | 'list' + | 'listbox' + | 'listitem' + | 'log' + | 'main' + | 'marquee' + | 'math' + | 'menu' + | 'menubar' + | 'menuitem' + | 'menuitemcheckbox' + | 'menuitemradio' + | 'meter' + | 'navigation' + | 'none' + | 'note' + | 'option' + | 'presentation' + | 'progressbar' + | 'radio' + | 'radiogroup' + | 'region' + | 'row' + | 'rowgroup' + | 'rowheader' + | 'scrollbar' + | 'search' + | 'searchbox' + | 'separator' + | 'slider' + | 'spinbutton' + | 'status' + | 'switch' + | 'tab' + | 'table' + | 'tablist' + | 'tabpanel' + | 'term' + | 'textbox' + | 'timer' + | 'toolbar' + | 'tooltip' + | 'tree' + | 'treegrid' + | 'treeitem'; + +export type AccessibilityKeys = keyof AriaAttributes; +export type AccessibilityProps = AriaAttributes; +export type AccessibilityMap = Record; + +export type AriaAttributes = { + role: AriaRoles; + /** + * Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application. + */ + activeDescendant?: string; + /** + * Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute. + */ + atomic?: boolean; + /** + * Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made. + */ + autoComplete?: 'none' | 'inline' | 'list' | 'both'; + /** + * Indicates an element is being modified and that assistive technologies MAY want to wait until the modifications are complete before exposing them to the user. + */ + busy?: boolean; + /** + * Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. + * @see aria-pressed @see aria-selected. + */ + checked?: boolean | 'mixed'; + /** + * Defines the total number of columns in a table, grid, or treegrid. + * @see aria-colindex. + */ + colCount?: number; + /** + * Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. + * @see aria-colcount @see aria-colspan. + */ + colIndex?: number; + /** + * Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. + * @see aria-colindex @see aria-rowspan. + */ + colSpan?: number; + /** + * Identifies the element (or elements) whose contents or presence are controlled by the current element. + * @see aria-owns. + */ + controls?: string; + /** + * Indicates the element that represents the current item within a container or set of related elements. + */ + current?: boolean | 'page' | 'step' | 'location' | 'date' | 'time'; + /** + * Identifies the element (or elements) that describes the object. + * @see aria-labelledby + */ + describedBy?: string; + /** + * Identifies the element that provides a detailed, extended description for the object. + * @see aria-describedby. + */ + details?: string; + /** + * Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. + * @see aria-hidden @see aria-readonly. + */ + disabled?: boolean; + /** + * Indicates what functions can be performed when a dragged object is released on the drop target. + * @deprecated in ARIA 1.1 + */ + dropEffect?: 'none' | 'copy' | 'execute' | 'link' | 'move' | 'popup'; + /** + * Identifies the element that provides an error message for the object. + * @see aria-invalid @see aria-describedby. + */ + errorMessage?: string; + /** + * Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed. + */ + expanded?: boolean; + /** + * Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, + * allows assistive technology to override the general default of reading in document source order. + */ + flowTo?: string; + /** + * Indicates an element's "grabbed" state in a drag-and-drop operation. + * @deprecated in ARIA 1.1 + */ + grabbed?: boolean; + /** + * Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. + */ + hasPopup?: boolean | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog'; + /** + * Indicates whether the element is exposed to an accessibility API. + * @see aria-disabled. + */ + hidden?: boolean; + /** + * Indicates the entered value does not conform to the format expected by the application. + * @see aria-errormessage. + */ + invalid?: boolean | 'grammar' | 'spelling'; + /** + * Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element. + */ + keyShortcuts?: string; + /** + * Defines a string value that labels the current element. + * @see aria-labelledby. + */ + label?: string; + /** + * Identifies the element (or elements) that labels the current element. + * @see aria-describedby. + */ + labelledBy?: string; + /** + * Defines the hierarchical level of an element within a structure. + */ + level?: number; + /** + * Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region. + */ + liveRegion?: 'off' | 'assertive' | 'polite'; + /** + * Indicates whether an element is modal when displayed. + */ + modal?: boolean; + /** + * Indicates whether a text box accepts multiple lines of input or only a single line. + */ + multiline?: boolean; + /** + * Indicates that the user may select more than one item from the current selectable descendants. + */ + multiSelectable?: boolean; + /** + * Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous. + */ + orientation?: 'horizontal' | 'vertical'; + /** + * Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship + * between DOM elements where the DOM hierarchy cannot be used to represent the relationship. + * @see aria-controls. + */ + owns?: string; + /** + * Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. + * A hint could be a sample value or a brief description of the expected format. + */ + placeholder?: string; + /** + * Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. + * @see aria-setsize. + */ + posInSet?: number; + /** + * Indicates the current "pressed" state of toggle buttons. + * @see aria-checked @see aria-selected. + */ + pressed?: boolean | 'mixed'; + /** + * Indicates that the element is not editable, but is otherwise operable. + * @see aria-disabled. + */ + readOnly?: boolean; + /** + * Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. + * @see aria-atomic. + */ + relevant?: + | 'additions' + | 'additions removals' + | 'additions text' + | 'all' + | 'removals' + | 'removals additions' + | 'removals text' + | 'text' + | 'text additions' + | 'text removals'; + /** + * Indicates that user input is required on the element before a form may be submitted. + */ + required?: boolean; + /** + * Defines a human-readable, author-localized description for the role of an element. + */ + roleDescription?: string; + /** + * Defines the total number of rows in a table, grid, or treegrid. + * @see aria-rowindex. + */ + rowCount?: number; + /** + * Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. + * @see aria-rowcount @see aria-rowspan. + */ + rowIndex?: number; + /** + * Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. + * @see aria-rowindex @see aria-colspan. + */ + rowSpan?: number; + /** + * Indicates the current "selected" state of various widgets. + * @see aria-checked @see aria-pressed. + */ + selected?: boolean; + /** + * Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. + * @see aria-posinset. + */ + setSize?: number; + /** + * Indicates if items in a table or grid are sorted in ascending or descending order. + */ + sort?: 'none' | 'ascending' | 'descending' | 'other'; + /** + * Defines the maximum allowed value for a range widget. + */ + valueMax?: number; + /** + * Defines the minimum allowed value for a range widget. + */ + valueMin?: number; + /** + * Defines the current value for a range widget. + * @see aria-valuetext. + */ + valueNow?: number; + /** + * Defines the human readable text alternative of aria-valuenow for a range widget. + */ + valueText?: string; +}; diff --git a/packages/blade-core/src/utils/makeAnalyticsAttribute/index.ts b/packages/blade-core/src/utils/makeAnalyticsAttribute/index.ts new file mode 100644 index 00000000000..b54d65740dd --- /dev/null +++ b/packages/blade-core/src/utils/makeAnalyticsAttribute/index.ts @@ -0,0 +1,2 @@ +export * from './makeAnalyticsAttribute'; +export * from './makeAnalyticsConstants'; diff --git a/packages/blade-core/src/utils/makeAnalyticsAttribute/makeAnalyticsAttribute.ts b/packages/blade-core/src/utils/makeAnalyticsAttribute/makeAnalyticsAttribute.ts new file mode 100644 index 00000000000..70a3d5c9a5e --- /dev/null +++ b/packages/blade-core/src/utils/makeAnalyticsAttribute/makeAnalyticsAttribute.ts @@ -0,0 +1,15 @@ +import type { DataAnalyticsAttribute } from '~utils/types'; + +const makeAnalyticsAttribute = (props: Record): DataAnalyticsAttribute => { + return Object.entries(props) + .filter(([key]) => key.startsWith('data-analytics')) + .reduce( + (acc, [key, value]) => ({ + ...acc, + [key]: value as string, + }), + {}, + ); +}; + +export { makeAnalyticsAttribute }; diff --git a/packages/blade-core/src/utils/makeAnalyticsAttribute/makeAnalyticsConstants.ts b/packages/blade-core/src/utils/makeAnalyticsAttribute/makeAnalyticsConstants.ts new file mode 100644 index 00000000000..d3cf51a00d1 --- /dev/null +++ b/packages/blade-core/src/utils/makeAnalyticsAttribute/makeAnalyticsConstants.ts @@ -0,0 +1,29 @@ +export const MAKE_ANALYTICS_CONSTANTS = { + ACCORDION: { + ACCORDION_ITEM_BUTTON: 'accordion-toggle-button', + }, + ALERT: { + PRIMARY_ACTION_BUTTON: 'alert-primary-action-button', + }, + AVATAR: { + AVATAR_BUTTON: 'avatar-button', + }, + CARD: { + FOOTER_PRIMARY_ACTION_BUTTON: 'card-footer-primary-action-button', + FOOTER_SECONDARY_ACTION_BUTTON: 'card-footer-secondary-action-button', + }, + DATE_PICKER: { + CANCEL_BUTTON: 'date-picker-cancel-button', + APPLY_BUTTON: 'date-picker-apply-button', + }, + FILE_UPLOAD: { + REUPLOAD_BUTTON: 'file-reupload-button', + }, + SPOTLIGHT_POPOVER_TOUR: { + FOOTER_PRIMARY_ACTION: 'spotlight-popover-tour-footer-primary-action-button', + FOOTER_SECONDARY_ACTION: 'spotlight-popover-tour-footer-secondary-action-button', + }, + TOAST: { + ACTION_BUTTON: 'toast-action-button', + }, +}; diff --git a/packages/blade-core/src/utils/metaAttribute/index.ts b/packages/blade-core/src/utils/metaAttribute/index.ts new file mode 100644 index 00000000000..3d6bc07a5c2 --- /dev/null +++ b/packages/blade-core/src/utils/metaAttribute/index.ts @@ -0,0 +1,2 @@ +export * from './metaAttribute'; +export * from './metaConstants'; diff --git a/packages/blade-core/src/utils/metaAttribute/metaAttribute.ts b/packages/blade-core/src/utils/metaAttribute/metaAttribute.ts new file mode 100644 index 00000000000..c469bcfa0c9 --- /dev/null +++ b/packages/blade-core/src/utils/metaAttribute/metaAttribute.ts @@ -0,0 +1,19 @@ +import { MetaConstants } from './metaConstants'; + +const metaAttribute = ({ + name, + testID, +}: { + name?: string; + testID?: string; +}): { + 'data-blade-component'?: string; + 'data-testid'?: string; +} => { + return { + ...(name ? { [`data-${MetaConstants.Component}`]: name } : {}), + ...(testID ? { [`data-testid`]: testID } : {}), + }; +}; + +export { metaAttribute }; diff --git a/packages/blade-core/src/utils/metaAttribute/metaConstants.ts b/packages/blade-core/src/utils/metaAttribute/metaConstants.ts new file mode 100644 index 00000000000..0c4b3a4774c --- /dev/null +++ b/packages/blade-core/src/utils/metaAttribute/metaConstants.ts @@ -0,0 +1,152 @@ +export const MetaConstants = { + Accordion: 'accordion', + AccordionButton: 'accordion-button', + AccordionItem: 'accordion-item', + AccordionItemHeader: 'accordion-item-header', + AccordionItemBody: 'accordion-item-body', + ActionList: 'action-list', + ActionListItem: 'action-list-item', + ActionListSection: 'action-list-section', + Alert: 'alert', + Amount: 'amount', + AutoComplete: 'autocomplete', + Avatar: 'avatar', + AvatarGroup: 'avatar-group', + Badge: 'badge', + BaseFilterChip: 'base-filter-chip', + Box: 'box', + BaseBox: 'base-box', + BaseText: 'base-text', + Button: 'button', + ButtonGroup: 'button-group', + Breadcrumb: 'breadcrumb', + BreadcrumbItem: 'breadcrumb-item', + BottomNav: 'bottomnav', + BottomNavItem: 'bottomnav-item', + Carousel: 'carousel', + ChatMessage: 'chat-message', + Checkbox: 'checkbox', + CheckboxGroup: 'checkbox-group', + CheckboxLabel: 'checkbox-label', + Chip: 'chip', + ChipGroup: 'chip-group', + ChipLabel: 'chip-label', + Code: 'code', + Component: 'blade-component', + Counter: 'counter', + Display: 'display', + Divider: 'divider', + Drawer: 'drawer', + EmptyState: 'empty-state', + Dropdown: 'dropdown', + DropdownOverlay: 'dropdown-overlay', + DropdownFooter: 'dropdown-footer', + DropdownHeader: 'dropdown-header', + DatePicker: 'datepicker', + Calendar: 'calendar', + FileUpload: 'file-upload', + FileUploadItem: 'file-upload-item', + FileUploadLabel: 'file-upload-label', + FilterChipGroup: 'filter-chip-group', + Icon: 'icon', + IconButton: 'icon-button', + InfoGroup: 'info-group', + InfoItem: 'info-item', + InfoItemKey: 'info-item-key', + InfoItemValue: 'info-item-value', + InfoItemIcon: 'info-item-icon', + Indicator: 'indicator', + InputGroup: 'input-group', + Link: 'link', + List: 'list', + ListItem: 'list-item', + ListItemCode: 'list-item-code', + ListItemLink: 'list-item-link', + ListItemText: 'list-item-text', + ListView: 'list-view', + ListViewFilter: 'list-view-filter', + OTPInput: 'otp-input', + PasswordInput: 'password-input', + SearchInput: 'search-input', + TextArea: 'textarea', + TextInput: 'textinput', + PhoneNumberInput: 'phone-number-input', + Toast: 'toast', + ToastContainer: 'toast-container', + TopNav: 'top-nav', + TopNavBrand: 'top-nav-brand', + TopNavContent: 'top-nav-content', + TopNavActions: 'top-nav-actions', + TabNav: 'tab-nav', + TabNavItems: 'tab-nav-items', + TabNavItem: 'tab-nav-item', + TabNavItemLink: 'tab-nav-item-link', + ProgressBar: 'progress-bar', + Radio: 'radio', + RadioGroup: 'radio-group', + RadioLabel: 'radio-label', + SkipNav: 'skipnav', + Spinner: 'spinner', + SideNav: 'sidenav', + SelectInput: 'select-input', + Tag: 'tag', + Tooltip: 'tooltip', + TooltipInteractiveWrapper: 'tooltip-interactive-wrapper', + Tabs: 'tabs', + TabList: 'tab-list', + TabItem: 'tab-item', + TabPanel: 'tab-panel', + TabIndicator: 'tab-indicator', + Table: 'table', + TableBody: 'table-body', + TableRow: 'table-row', + TableCell: 'table-cell', + TableCellWrapper: 'table-cell-wrapper', + TableSortButton: 'table-sort-button', + TableHeader: 'table-header', + TableHeaderRow: 'table-header-row', + TableHeaderCell: 'table-header-cell', + TableFooter: 'table-footer', + TableFooterRow: 'table-footer-row', + TableFooterCell: 'table-footer-cell', + TableElement: 'table-element', + TablePageSelectionButton: 'table-page-selection-button', + TourPopover: 'tour-popover', + TourMask: 'tour-mask', + Popover: 'popover', + PopoverInteractiveWrapper: 'popover-interactive-wrapper', + BottomSheet: 'bottom-sheet', + BottomSheetBody: 'bottom-sheet-body', + BottomSheetHeader: 'bottom-sheet-header', + BottomSheetFooter: 'bottom-sheet-footer', + BottomSheetGrabHandle: 'bottomsheet-grab-handle', + Card: 'card', + CardBody: 'card-body', + CardHeader: 'card-header', + CardFooter: 'card-footer', + Collapsible: 'collapsible', + CollapsibleBody: 'collapsible-body', + CollapsibleButton: 'collapsible-button', + CollapsibleLink: 'collapsible-link', + Menu: 'menu', + MenuHeader: 'menu-header', + MenuFooter: 'menu-footer', + Modal: 'modal', + ModalBody: 'modal-body', + ModalHeader: 'modal-header', + ModalFooter: 'modal-footer', + ModalBackdrop: 'modal-backdrop', + ModalScrollOverlay: 'modal-scroll-overlay', + VisuallyHidden: 'visually-hidden', + FormLabel: 'form-label', + Switch: 'switch', + SwitchLabel: 'switch-label', + StyledBaseInput: 'styled-base-input', + Skeleton: 'skeleton', + StepGroup: 'step-group', + StepItem: 'step-item', + PreviewWindow: 'preview-window', + PreviewHeader: 'preview-header', + PreviewBody: 'preview-body', + PreviewFooter: 'preview-footer', +} as const; diff --git a/packages/blade-svelte/package.json b/packages/blade-svelte/package.json index ab73ebbe0a9..1dc0588e95f 100644 --- a/packages/blade-svelte/package.json +++ b/packages/blade-svelte/package.json @@ -10,6 +10,10 @@ "check": "svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch" }, + "dependencies": { + "class-variance-authority": "^0.7.0", + "@razorpay/blade-core": "0.0.1" + }, "devDependencies": { "@sveltejs/vite-plugin-svelte": "^4.0.0", "@types/node": "^20.0.0", diff --git a/packages/blade-svelte/src/App.svelte b/packages/blade-svelte/src/App.svelte index 1b3be6946ea..e5a0dbc3eff 100644 --- a/packages/blade-svelte/src/App.svelte +++ b/packages/blade-svelte/src/App.svelte @@ -1,18 +1,64 @@
+

Button Component

+ +

Link Component - Anchor Variant

+ + +

Link Component - Button Variant

+ + +

Link Component - Sizes

+
@@ -26,5 +72,16 @@ .component-container { padding: var(--spacing-4); + display: flex; + flex-direction: column; + gap: var(--spacing-6); + align-items: flex-start; + } + + .link-examples { + display: flex; + flex-direction: column; + gap: var(--spacing-3); + align-items: flex-start; } diff --git a/packages/blade-svelte/src/components/Link/BaseLink/BaseLink.svelte b/packages/blade-svelte/src/components/Link/BaseLink/BaseLink.svelte new file mode 100644 index 00000000000..69d4657aa19 --- /dev/null +++ b/packages/blade-svelte/src/components/Link/BaseLink/BaseLink.svelte @@ -0,0 +1,292 @@ + + + + + {#if Icon && iconPosition === 'left'} + + + + {/if} + {#if children} + + + {@render children()} + + {/if} + {#if Icon && iconPosition === 'right'} + + + + {/if} + + + diff --git a/packages/blade-svelte/src/components/Link/BaseLink/baseLink.css b/packages/blade-svelte/src/components/Link/BaseLink/baseLink.css new file mode 100644 index 00000000000..6a12d4ea38a --- /dev/null +++ b/packages/blade-svelte/src/components/Link/BaseLink/baseLink.css @@ -0,0 +1,65 @@ +.base-link { + padding: 0; + background-color: transparent; + outline: none; + text-decoration: none; + border: none; + cursor: pointer; + display: inline-block; + border-radius: var(--border-radius-small); + transition-property: box-shadow, color, fill; + transition-timing-function: var(--motion-easing-standard); + transition-duration: var(--motion-duration-2xquick); +} + +/* Focus ring is handled by utility class in theme.css */ + +.base-link[disabled] { + cursor: not-allowed; +} + +.base-link__content { + display: flex; + flex-direction: row; + align-items: center; + width: max-content; + border-radius: var(--border-radius-small); +} + +.base-link__icon { + display: flex; + align-items: center; +} + +.base-link__text { + font-weight: var(--font-weight-medium); + text-align: center; + transition-property: color, fill; + transition-timing-function: var(--motion-easing-standard); + transition-duration: var(--motion-duration-2xquick); +} + +/* TODO: Will migrate it to Text Component once we have typegraphy in place */ +.base-link__text--xsmall { + font-size: var(--font-size-25); + line-height: var(--line-height-25); +} + +.base-link__text--small { + font-size: var(--font-size-75); + line-height: var(--line-height-75); +} + +.base-link__text--medium { + font-size: var(--font-size-100); + line-height: var(--line-height-100); +} + +.base-link__text--large { + font-size: var(--font-size-200); + line-height: var(--line-height-200); +} + +.base-link--text--underline { + text-decoration: underline; +} diff --git a/packages/blade-svelte/src/components/Link/Link.svelte b/packages/blade-svelte/src/components/Link/Link.svelte new file mode 100644 index 00000000000..b1527ae55eb --- /dev/null +++ b/packages/blade-svelte/src/components/Link/Link.svelte @@ -0,0 +1,102 @@ + + + + diff --git a/packages/blade-svelte/src/theme/theme.css b/packages/blade-svelte/src/theme/theme.css index 310eadcab35..97fd3514c28 100644 --- a/packages/blade-svelte/src/theme/theme.css +++ b/packages/blade-svelte/src/theme/theme.css @@ -808,3 +808,26 @@ --line-height-1100: 48px; } } + + +.cursor-not-allowed { + cursor: not-allowed; +} + +.cursor-pointer { + cursor: pointer; +} + +.text-underline { + text-decoration: underline; +} + +/* Focus Ring Utility */ +.focus-ring:focus-visible { + box-shadow: 0px 0px 0px 4px var(--interactive-background-primary-faded); +} + +/* Focus Ring for child elements (when parent receives focus) */ +.focus-ring-parent:focus-visible .focus-ring-child { + box-shadow: 0px 0px 0px 4px var(--interactive-background-primary-faded); +} \ No newline at end of file diff --git a/packages/blade-svelte/src/types.d.ts b/packages/blade-svelte/src/types.d.ts new file mode 100644 index 00000000000..3cd510fccc9 --- /dev/null +++ b/packages/blade-svelte/src/types.d.ts @@ -0,0 +1,12 @@ +export type ActionStatesType = 'default' | 'hover' | 'focus' | 'disabled'; + +export type ColorType = 'normal' | 'subtle' | 'disabled'; + +export interface UseInteractionReturnType { + currentInteraction: ActionStates; + setCurrentInteraction: (state: ActionStates) => void; + onMouseEnter: () => void; + onMouseLeave: () => void; + onFocus: () => void; + onBlur: () => void; +} \ No newline at end of file diff --git a/packages/blade-svelte/src/utils/index.ts b/packages/blade-svelte/src/utils/index.ts new file mode 100644 index 00000000000..69c2a3d8112 --- /dev/null +++ b/packages/blade-svelte/src/utils/index.ts @@ -0,0 +1 @@ +export * from './useInteraction'; diff --git a/packages/blade-svelte/src/utils/useInteraction.ts b/packages/blade-svelte/src/utils/useInteraction.ts new file mode 100644 index 00000000000..31586d961b5 --- /dev/null +++ b/packages/blade-svelte/src/utils/useInteraction.ts @@ -0,0 +1,44 @@ +import type { ActionStatesType, UseInteractionReturnType } from '../types'; + +/** + * Hook for managing interaction states (default, hover, focus, disabled) + * Similar to React's useInteraction hook + * + * This function returns handlers that work with state created in the component. + * The component should create the state using $state and pass a setter function. + * + * @param getState - Function to get current state + * @param setState - Function to set state + * @returns Object with event handlers + */ +export function useInteraction( + getState: () => ActionStatesType, + setState: (state: ActionStatesType) => void, +): Omit { + const onMouseEnter = (): void => { + if (getState() !== 'focus') { + setState('hover'); + } + }; + + const onMouseLeave = (): void => { + if (getState() !== 'focus') { + setState('default'); + } + }; + + const onFocus = (): void => { + setState('focus'); + }; + + const onBlur = (): void => { + setState('default'); + }; + + return { + onMouseEnter, + onMouseLeave, + onFocus, + onBlur, + }; +} diff --git a/yarn.lock b/yarn.lock index c424276eac7..37386d0ed90 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13460,6 +13460,13 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +class-variance-authority@^0.7.0: + version "0.7.1" + resolved "https://registry.yarnpkg.com/class-variance-authority/-/class-variance-authority-0.7.1.tgz#4008a798a0e4553a781a57ac5177c9fb5d043787" + integrity sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg== + dependencies: + clsx "^2.1.1" + clean-css@^4.2.3: version "4.2.4" resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.4.tgz#733bf46eba4e607c6891ea57c24a989356831178" @@ -29981,7 +29988,7 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -29999,6 +30006,15 @@ string-width@^1.0.1: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + string-width@^5.0.0, string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -30119,7 +30135,7 @@ stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -30140,6 +30156,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -32908,7 +32931,7 @@ worker-rpc@^0.1.0: dependencies: microevent.ts "~0.1.1" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -32926,6 +32949,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"