-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve code related to
OAuth
section (#11954)
* chore: improve code related to `OAuth` section - Removed the `useOAuthProviderSelect` hook - Cleaned up the `OAuthProviderInstructions` component - Introduced the new `PreviewProviders` component - Added the `useSelectCombobox` hook - Created a `hooks` folder and update the `tsconfig.json` paths * chore: update `highlighter` function - Replace `getHighlighter` with `createHighlighter` - Ensure compatibility with existing functionality
- Loading branch information
1 parent
2922e28
commit 00b16ae
Showing
6 changed files
with
138 additions
and
118 deletions.
There are no files selected for viewing
This file contains 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 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
32 changes: 0 additions & 32 deletions
32
docs/components/OAuthProviderInstructions/useOAuthProviderSelect.ts
This file was deleted.
Oops, something went wrong.
This file contains 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,35 @@ | ||
export interface Provider { | ||
id: string | ||
name: string | ||
} | ||
|
||
export interface PreviewProvidersProps { | ||
className?: string | ||
providers: Provider[] | ||
onSelected: (provider: Provider) => void | ||
} | ||
|
||
export function PreviewProviders({ | ||
className, | ||
providers, | ||
onSelected, | ||
}: PreviewProvidersProps) { | ||
return ( | ||
<section className={className}> | ||
{providers.map((provider) => ( | ||
<div | ||
className="flex h-32 w-32 min-w-24 flex-col items-center justify-between rounded-lg border border-solid border-neutral-200 p-4 shadow-sm transition-colors duration-300 hover:bg-neutral-50 dark:border-neutral-800 dark:hover:bg-neutral-950" | ||
key={provider.id} | ||
role="button" | ||
onClick={() => onSelected(provider)} | ||
> | ||
<img | ||
src={`/img/providers/${provider.id}.svg`} | ||
className="mt-2 w-11" | ||
/> | ||
<div className="text-center text-sm">{provider.name}</div> | ||
</div> | ||
))} | ||
</section> | ||
) | ||
} |
This file contains 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,48 @@ | ||
import { ChangeEvent, useState } from "react" | ||
|
||
interface SelectComboboxValue { | ||
id: string | ||
name: string | ||
} | ||
|
||
interface SelectComboboxProps { | ||
defaultValue?: SelectComboboxValue | ||
items: SelectComboboxValue[] | ||
} | ||
|
||
export const useSelectCombobox = ({ | ||
defaultValue = { id: "", name: "" }, | ||
items, | ||
}: SelectComboboxProps) => { | ||
const [selectedItem, setSelectedItem] = | ||
useState<SelectComboboxValue>(defaultValue) | ||
const [filteredItems, setFilteredItems] = useState(items) | ||
const [hasMatchItem, setHasMatchItem] = useState(false) | ||
|
||
const handleSelect = (value: SelectComboboxValue) => { | ||
let hasMatchItem = false | ||
setFilteredItems( | ||
items.filter((item) => { | ||
if (item.id === value.id) { | ||
hasMatchItem = true | ||
} | ||
return item.name.toLowerCase().includes(value.name.toLowerCase()) | ||
}) | ||
) | ||
setSelectedItem(value) | ||
setHasMatchItem(hasMatchItem) | ||
} | ||
|
||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
const { value } = event.target | ||
handleSelect({ id: value, name: value }) | ||
} | ||
|
||
return { | ||
selectedItem, | ||
filteredItems, | ||
handleSelect, | ||
handleChange, | ||
hasMatchItem, | ||
} | ||
} |
This file contains 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