Skip to content

Commit

Permalink
Merge pull request #1237 from lpsinger/modularize-css
Browse files Browse the repository at this point in the history
Factor out component-specific CSS into modules
  • Loading branch information
dakota002 authored Aug 16, 2023
2 parents 17a071e + 3e06a70 commit 6221ea6
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 530 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ sam.json
sam.yaml

# Generated by sass
/app/css
/app/**/*.css
/app/**/*.css.map

.env
.eslintcache
2 changes: 1 addition & 1 deletion app/components/NoticeTypeCheckboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
import { useState } from 'react'

import { NestedCheckboxes } from './NestedCheckboxes'
import type { NoticeFormat } from './NoticeFormat'
import { NestedCheckboxes } from './nested-checkboxes/NestedCheckboxes'
import { triggerRate } from '~/lib/prometheus'

function humanizedCount(count: number, singular: string, plural?: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Link } from '@remix-run/react'
import { Checkbox } from '@trussworks/react-uswds'
import { useEffect, useRef, useState } from 'react'

import styles from './nested-checkboxes.module.css'

type CheckboxArgs = Parameters<typeof Checkbox>
type CheckboxProps = CheckboxArgs[0]
interface NestedCheckboxProps extends CheckboxProps {
Expand Down Expand Up @@ -70,7 +72,7 @@ function NestedCheckboxNode({
aria-expanded={expanded}
aria-selected={false}
onClick={() => setExpanded(!expanded)}
className="nested-checkboxes__node"
className={styles.node}
>
<Checkbox
className="display-inline-block"
Expand Down Expand Up @@ -107,7 +109,7 @@ function NestedCheckboxNode({
})
}}
/>
<ul hidden={!expanded} className="nested-checkboxes__leaf">
<ul hidden={!expanded} className={styles.leaf}>
{nodes.map((node, index) => (
<li role="treeitem" key={index} aria-selected={false}>
<Checkbox
Expand Down
24 changes: 24 additions & 0 deletions app/components/nested-checkboxes/nested-checkboxes.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.node {
& {
list-style: url('~/../node_modules/nasawds/src/img/usa-icons/chevron_right.svg');
}

&[aria-expanded='true'] {
list-style: url('~/../node_modules/nasawds/src/img/usa-icons/expand_more.svg');
}

& [data-testid='checkbox'] {
position: relative;
top: -0.25rem;
display: inline-block;
}

& label {
margin-top: 0;
margin-bottom: 0.5rem;
}
}

.leaf {
list-style: none;
}
4 changes: 3 additions & 1 deletion app/components/Tabs.tsx → app/components/tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
import { useState } from 'react'

import styles from './tabs.module.css'

export interface TabProps {
label: React.ReactNode
children: React.ReactNode
Expand All @@ -24,7 +26,7 @@ export function Tabs({
const [selectedTab, setSelectedTab] = useState(0)

return (
<div className="tabs-component">
<div className={styles.tabs}>
<div role="tablist">
{children.map((tab, index) => (
<button
Expand Down
46 changes: 46 additions & 0 deletions app/components/tabs/tabs.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.tabs {
& [role='tablist'] {
& {
display: flex;
flex-wrap: wrap;
border-bottom: 1px solid #dee2e6;
position: relative;
}

& button {
& {
border-width: 1px;
border-style: solid;
border-color: transparent;
border-top-left-radius: 0;
border-top-right-radius: 0;
display: block;
padding: 0.5rem 1rem;
cursor: pointer;
margin: 0;
outline: none;
background-color: #fff;
transition: border 0.2s ease-in-out 0s;
}

&.active,
&:focus,
&:hover {
border-width: 1px;
border-color: #e9ecef #e9ecef #b41c1c;
}

&.active {
color: #495057;
background-color: #f8f8f8;
}
}
}

& [role='tabpanel'] {
text-align: left;
padding: 1rem;
background-color: #f8f8f8;
box-shadow: 1px 1px 2px rgb(204 204 204 / 75%);
}
}
4 changes: 3 additions & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
*
*/
import { cssBundleHref } from '@remix-run/css-bundle'
import type {
DataFunctionArgs,
LinksFunction,
Expand Down Expand Up @@ -73,7 +74,7 @@ import favicon_72 from '~/../node_modules/nasawds/src/img/favicons/favicon-72.pn
import favicon_114 from '~/../node_modules/nasawds/src/img/favicons/favicon-114.png'
import favicon_144 from '~/../node_modules/nasawds/src/img/favicons/favicon-144.png'
import favicon_192 from '~/../node_modules/nasawds/src/img/favicons/favicon-192.png'
import themeStyle from '~/css/custom.css'
import themeStyle from '~/theme.css'

const favicons = {
16: favicon_16,
Expand Down Expand Up @@ -117,6 +118,7 @@ export const links: LinksFunction = () => [
rel: 'stylesheet',
href: highlightStyle,
},
...(cssBundleHref ? [{ rel: 'stylesheet', href: cssBundleHref }] : []),
...Object.entries(favicons).map(([size, href]) => ({
rel: 'icon',
href: href,
Expand Down
2 changes: 1 addition & 1 deletion app/routes/docs_.schema.$version.$/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './components'
import { Highlight } from '~/components/Highlight'
import { SideNavSub } from '~/components/SideNav'
import { Tab, Tabs } from '~/components/Tabs'
import { Tab, Tabs } from '~/components/tabs/Tabs'
import { publicStaticShortTermCacheControlHeaders } from '~/lib/headers.server'
import type { ExampleFiles, GitContentDataResponse } from '~/lib/schema-data'
import {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/quickstart.code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Button, ButtonGroup, FormGroup } from '@trussworks/react-uswds'

import { ClientCredentialVendingMachine } from './user.credentials/client_credentials.server'
import { ClientSampleCode } from '~/components/ClientSampleCode'
import { Tab, Tabs } from '~/components/Tabs'
import { Tab, Tabs } from '~/components/tabs/Tabs'
import { formatAndNoticeTypeToTopic } from '~/lib/utils'

export const handle = {
Expand Down
Loading

0 comments on commit 6221ea6

Please sign in to comment.