-
Notifications
You must be signed in to change notification settings - Fork 173
Added Link Component to Svelte | Cursor Rules for Effecient React to Svelte Migration #3020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kashishbehl
wants to merge
3
commits into
feat/svelte-impl
Choose a base branch
from
feat/component/Link.svelte
base: feat/svelte-impl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/blade-core/src/utils/makeAccessible/accessibilityMap.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './makeAccessible'; | ||
| export * from './types'; |
27 changes: 27 additions & 0 deletions
27
packages/blade-core/src/utils/makeAccessible/makeAccessible.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<AccessibilityProps>): Record<string, unknown> => { | ||
| const newProps: Record<string, any> = {}; | ||
|
|
||
| // 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; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice