Browse Source

[Beta]Move all possible style to tailwind classes (#4054)

* Move all possible style to tailwind classes

* Update Sidebar.tsx

* fix-collapsable-color

* dry run and commit

* Update SidebarLink.tsx

* Fixes review comments for aria tags

* Remove extended tailwind configs

* Update tailwind.config.js

* Update Sidebar.tsx
main
Strek 3 years ago
committed by GitHub
parent
commit
01afd01325
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      beta/src/components/Layout/Page.tsx
  2. 10
      beta/src/components/Layout/Sidebar/Sidebar.tsx
  3. 3
      beta/src/components/Layout/Sidebar/SidebarRouteTree.tsx
  4. 3
      beta/src/components/MDX/APIAnatomy.tsx
  5. 10
      beta/src/components/MDX/Heading.tsx
  6. 46
      beta/src/components/MDX/Sandpack/Preview.tsx
  7. 3
      beta/src/components/Search.tsx

4
beta/src/components/Layout/Page.tsx

@ -25,9 +25,7 @@ export function Page({routeTree, children}: PageProps) {
<div className="flex flex-1 w-full h-full self-stretch"> <div className="flex flex-1 w-full h-full self-stretch">
<div className="w-full min-w-0"> <div className="w-full min-w-0">
<main <main className="flex flex-1 self-stretch flex-col items-end justify-around">
className="flex flex-1 self-stretch flex-col items-end"
style={{justifyContent: 'space-around'}}>
{children} {children}
<Footer /> <Footer />
</main> </main>

10
beta/src/components/Layout/Sidebar/Sidebar.tsx

@ -18,7 +18,7 @@ export function Sidebar({isMobileOnly}: {isMobileOnly?: boolean}) {
const {menuRef, isOpen} = React.useContext(MenuContext); const {menuRef, isOpen} = React.useContext(MenuContext);
const isMobileSidebar = useMediaQuery(SIDEBAR_BREAKPOINT); const isMobileSidebar = useMediaQuery(SIDEBAR_BREAKPOINT);
let routeTree = React.useContext(SidebarContext); let routeTree = React.useContext(SidebarContext);
const isHidden = isMobileOnly && !isMobileSidebar; const isHidden = isMobileSidebar ? !isOpen : false;
// HACK. Fix up the data structures instead. // HACK. Fix up the data structures instead.
if ((routeTree as any).routes.length === 1) { if ((routeTree as any).routes.length === 1) {
@ -62,14 +62,10 @@ export function Sidebar({isMobileOnly}: {isMobileOnly?: boolean}) {
return ( return (
<aside <aside
className={cn( className={cn(
`lg:flex-grow lg:flex flex-col w-full pt-4 pb-8 lg:pb-0 lg:max-w-xs fixed lg:sticky bg-wash dark:bg-wash-dark z-10`, `lg:flex-grow lg:flex flex-col w-full pt-4 pb-8 lg:pb-0 lg:max-w-xs fixed lg:sticky bg-wash dark:bg-wash-dark z-10 top-0`,
isOpen ? 'block z-40' : 'hidden lg:block' isOpen ? 'block z-40' : 'hidden lg:block'
)} )}
aria-hidden={isHidden ? 'true' : 'false'} aria-hidden={isHidden}>
style={{
top: 0,
visibility: isHidden ? 'hidden' : undefined,
}}>
<div className="px-5"> <div className="px-5">
<Search /> <Search />
</div> </div>

3
beta/src/components/Layout/Sidebar/SidebarRouteTree.tsx

@ -3,6 +3,7 @@
*/ */
import * as React from 'react'; import * as React from 'react';
import cn from 'classnames';
import {RouteItem} from 'components/Layout/useRouteMeta'; import {RouteItem} from 'components/Layout/useRouteMeta';
import {useRouter} from 'next/router'; import {useRouter} from 'next/router';
import {removeFromLast} from 'utils/removeFromLast'; import {removeFromLast} from 'utils/removeFromLast';
@ -59,8 +60,8 @@ function CollapseWrapper({
return ( return (
<div <div
ref={ref} ref={ref}
className={cn(isExpanded ? 'opacity-100' : 'opacity-50')}
style={{ style={{
opacity: isExpanded ? 1 : 0.5,
transition: `opacity ${duration}ms ease-in-out`, transition: `opacity ${duration}ms ease-in-out`,
animation: `nav-fadein ${duration}ms ease-in-out`, animation: `nav-fadein ${duration}ms ease-in-out`,
}}> }}>

3
beta/src/components/MDX/APIAnatomy.tsx

@ -101,9 +101,6 @@ export function AnatomyStep({
const color = colors[stepNumber - 1]; const color = colors[stepNumber - 1];
return ( return (
<div <div
style={{
borderLeftColor: color.hex,
}}
className={cn( className={cn(
'border-l-4 rounded-lg px-5 pt-8 pb-2 bg-opacity-5 shadow-inner', 'border-l-4 rounded-lg px-5 pt-8 pb-2 bg-opacity-5 shadow-inner',
color.border, color.border,

10
beta/src/components/MDX/Heading.tsx

@ -27,11 +27,11 @@ const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading(
{isPageAnchor && ( {isPageAnchor && (
<a <a
href={`#${id}`} href={`#${id}`}
className={anchorClassName} className={cn(
aria-hidden={true} anchorClassName,
style={{ Comp === 'h1' ? 'hidden' : 'inline-block'
display: Comp === 'h1' ? 'none' : 'inline-block', )}
}}> aria-hidden="true">
<svg <svg
width="1em" width="1em"
height="1em" height="1em"

46
beta/src/components/MDX/Sandpack/Preview.tsx

@ -100,16 +100,6 @@ export function Preview({
: null; : null;
const hideContent = !isReady || error; const hideContent = !isReady || error;
// Allow content to be scrolled if it's too high to fit.
// Note we don't want this in the expanded state
// because it breaks position: sticky (and isn't needed anyway).
// We also don't want this for errors because they expand
// parent and making them scrollable is confusing.
let overflow;
if (!isExpanded && !error && isReady) {
overflow = 'auto';
}
// WARNING: // WARNING:
// The layout and styling here is convoluted and really easy to break. // The layout and styling here is convoluted and really easy to break.
// If you make changes to it, you need to test different cases: // If you make changes to it, you need to test different cases:
@ -136,9 +126,14 @@ export function Preview({
}}> }}>
<div <div
className={cn( className={cn(
'p-0 sm:p-2 md:p-4 lg:p-8 bg-card dark:bg-wash-dark h-full relative rounded-b-lg lg:rounded-b-none' 'p-0 sm:p-2 md:p-4 lg:p-8 bg-card dark:bg-wash-dark h-full relative rounded-b-lg lg:rounded-b-none',
)} // Allow content to be scrolled if it's too high to fit.
style={{overflow}}> // Note we don't want this in the expanded state
// because it breaks position: sticky (and isn't needed anyway).
// We also don't want this for errors because they expand
// parent and making them scrollable is confusing.
!isExpanded && !error && isReady ? 'overflow-auto' : null
)}>
<div <div
style={{ style={{
padding: 'initial', padding: 'initial',
@ -151,31 +146,32 @@ export function Preview({
}}> }}>
<iframe <iframe
ref={iframeRef} ref={iframeRef}
className="rounded-t-none bg-white shadow-md sm:rounded-lg w-full max-w-full" className={cn(
title="Sandbox Preview" 'rounded-t-none bg-white shadow-md sm:rounded-lg w-full max-w-full',
style={{
height: iframeComputedHeight || '100%',
position: hideContent ? 'absolute' : undefined,
// We can't *actually* hide content because that would // We can't *actually* hide content because that would
// break calculating the computed height in the iframe // break calculating the computed height in the iframe
// (which we're using for autosizing). This is noticeable // (which we're using for autosizing). This is noticeable
// if you make a compiler error and then fix it with code // if you make a compiler error and then fix it with code
// that expands the content. You want to measure that. // that expands the content. You want to measure that.
opacity: hideContent ? 0 : 1, hideContent
pointerEvents: hideContent ? 'none' : undefined, ? 'absolute opacity-0 pointer-events-none'
: 'opacity-100'
)}
title="Sandbox Preview"
style={{
height: iframeComputedHeight || '100%',
zIndex: isExpanded ? 'initial' : -1, zIndex: isExpanded ? 'initial' : -1,
}} }}
/> />
</div> </div>
{error && ( {error && (
<div <div
className="p-2" className={cn(
style={{ 'p-2',
// This isn't absolutely positioned so that // This isn't absolutely positioned so that
// the errors can also expand the parent height. // the errors can also expand the parent height.
position: isExpanded ? 'sticky' : undefined, isExpanded ? 'sticky top-8' : null
top: isExpanded ? '2rem' : '', )}>
}}>
<Error error={error} /> <Error error={error} />
</div> </div>
)} )}

3
beta/src/components/Search.tsx

@ -31,8 +31,7 @@ function Hit({hit, children}: any) {
function Kbd(props: {children?: React.ReactNode}) { function Kbd(props: {children?: React.ReactNode}) {
return ( return (
<kbd <kbd
className="border border-transparent mr-1 bg-wash dark:bg-wash-dark text-gray-30 align-middle p-0 inline-flex justify-center items-center text-xs text-center rounded" className="h-6 w-6 border border-transparent mr-1 bg-wash dark:bg-wash-dark text-gray-30 align-middle p-0 inline-flex justify-center items-center text-xs text-center rounded"
style={{width: '2.25em', height: '2.25em'}}
{...props} {...props}
/> />
); );

Loading…
Cancel
Save