-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove @reach/skip-nav from the dependencies (#1051)
* chore: remove reach-ui from the dependencies and create the SkipNavLink/SkipNavContent components * chore: add @reach/skip-nav license note
- Loading branch information
Mark Arseneault
committed
Dec 9, 2022
1 parent
5a620ff
commit da3252d
Showing
8 changed files
with
94 additions
and
42 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* The code included in this file is inspired by https://github.com/reach/reach-ui/blob/43f450db7bcb25a743121fe31355f2294065a049/packages/skip-nav/src/reach-skip-nav.tsx which is part of the @reach/skip-nav library. | ||
* | ||
* @reach/skip-nav is licensed as follows: | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2018-2022, React Training LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* Source: https://github.com/reach/reach-ui/blob/43f450db7bcb25a743121fe31355f2294065a049/LICENSE | ||
*/ | ||
import React, { forwardRef, ComponentProps, ReactElement } from 'react' | ||
import cn from 'clsx' | ||
|
||
// TODO: Change the DEFAULT_ID for `nextra-skip-nav` or something else on the next major version (v3.x). The DEFAULT_ID must be 'reach-skip-nav' because changing this value is a breaking change for users that use v2.0.1 and earlier | ||
const DEFAULT_ID = 'reach-skip-nav' | ||
const DEFAULT_LABEL = 'Skip to content' | ||
|
||
type SkipNavLinkProps = Omit< | ||
ComponentProps<'a'>, | ||
'ref' | 'href' | 'children' | ||
> & { | ||
label?: string | ||
styled?: boolean | ||
} | ||
|
||
export const SkipNavLink = forwardRef<HTMLAnchorElement, SkipNavLinkProps>( | ||
function ( | ||
{ | ||
className: providedClassName, | ||
id, | ||
label = DEFAULT_LABEL, | ||
styled, | ||
...props | ||
}, | ||
forwardedRef | ||
): ReactElement { | ||
const className = | ||
providedClassName !== undefined // Give the option to the user to pass a falsy other than undefined to remove the default styles | ||
? providedClassName | ||
: styled // Give the user a way to opt-in the default style provided with the theme. Probably remove this option in the next major version (v3.x) and just do a check to use the providedClassName or the default | ||
? cn( | ||
'nx-sr-only', | ||
'focus:nx-not-sr-only focus:nx-fixed focus:nx-z-50 focus:nx-m-3 focus:nx-ml-4 focus:nx-h-[calc(var(--nextra-navbar-height)-1.5rem)] focus:nx-rounded-lg focus:nx-border focus:nx-px-3 focus:nx-py-2 focus:nx-align-middle focus:nx-text-sm focus:nx-font-bold', | ||
'focus:nx-text-gray-900 focus:dark:nx-text-gray-100', | ||
'focus:nx-bg-white focus:dark:nx-bg-neutral-900', | ||
'focus:nx-border-neutral-400 focus:dark:nx-border-neutral-800' | ||
) | ||
: '' | ||
|
||
return ( | ||
<a | ||
{...props} | ||
ref={forwardedRef} | ||
href={`#${id || DEFAULT_ID}`} | ||
className={className} | ||
// TODO: Remove in version v3.x. Must keep for compability reasons | ||
data-reach-skip-link="" | ||
> | ||
{label} | ||
</a> | ||
) | ||
} | ||
) | ||
|
||
type SkipNavContentProps = Omit<ComponentProps<'div'>, 'ref' | 'children'> | ||
|
||
export const SkipNavContent = forwardRef<HTMLDivElement, SkipNavContentProps>( | ||
function ({ id, ...props }, forwardedRef): ReactElement { | ||
return <div {...props} ref={forwardedRef} id={id || DEFAULT_ID} /> | ||
} | ||
) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
da3252d
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.
Successfully deployed to the following URLs:
nextra-v2 – ./docs
nextra.vercel.app
nextra-v2-shuding1.vercel.app
nextra-v2-git-main-shuding1.vercel.app
nextra-v2.vercel.app
nextra.site
www.nextra.site