Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/javascript/packages/components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `@18f/identity-components`

React components for common UI interactions. These components are intended to be general-purpose and
reusable, whereas domain-specific React components should be found in the package corresponding to
the specific page or feature.

Many of these components are React implementations for components of the [Login.gov Design System](https://design.login.gov/).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a rule we could enforce/lint on if we wanted, maybe. Like each React component in this dir should have a comment/metadata attribute of some sort that links to its corresponding LGDS component?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a hard rule, since we have some components which don't map directly to a design system component (e.g. PageHeader). Conversely, we have some design system components which live elsewhere (e.g. step-indicator).

In an ideal world, I'd like to move more toward per-component packages (also aligns with newer USWDS direction). But I also think that might be a bit too much overhead and may be on the more extreme side of granularity, impacting usability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an ideal world, I'd like to move more toward per-component packages (also aligns with newer USWDS direction). But I also think that might be a bit too much overhead and may be on the more extreme side of granularity, impacting usability.

On the other hand, the overhead could be a good thing to require more conscious effort to introducing these generalized components, since I think this current components package is too much at risk of including any and all sorts of React components. Plus, it would resolve the current inconsistency of some components living in this package, while others have their own package.


## Example

```tsx
import { Button } from '@18f/identity-components';

function MyComponent() {
return <Button isUnstyled>Continue</Button>;
}
```
2 changes: 0 additions & 2 deletions app/javascript/packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export { default as IconListItem } from './icon-list/icon-list-item';
export { default as IconListTitle } from './icon-list/icon-list-title';
export { default as Link } from './link';
export { default as PageFooter } from './page-footer';
export { default as LocationCollection } from './location-collection';
export { default as LocationCollectionItem } from './location-collection-item';
export { default as PageHeading } from './page-heading';
export { default as ProcessList } from './process-list/process-list';
export { default as ProcessListHeading } from './process-list/process-list-heading';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { useState, useEffect, useCallback, useRef } from 'react';
import { useI18n } from '@18f/identity-react-i18n';
import {
PageHeading,
LocationCollectionItem,
LocationCollection,
SpinnerDots,
} from '@18f/identity-components';
import { PageHeading, SpinnerDots } from '@18f/identity-components';
import BackButton from './back-button';
import LocationCollection from './location-collection';
import LocationCollectionItem from './location-collection-item';

interface PostOffice {
address: string;
Expand Down Expand Up @@ -160,33 +157,36 @@ function InPersonLocationStep({ onChange, toPreviousStep }) {
};
}, []);

let locationItems: React.ReactNode;
let locationsContent: React.ReactNode;
if (!isLoadingComplete) {
locationItems = <SpinnerDots />;
locationsContent = <SpinnerDots />;
} else if (locationData.length < 1) {
locationItems = <h4>{t('in_person_proofing.body.location.none_found')}</h4>;
locationsContent = <h4>{t('in_person_proofing.body.location.none_found')}</h4>;
} else {
locationItems = locationData.map((item, index) => (
<LocationCollectionItem
key={`${index}-${item.name}`}
handleSelect={handleLocationSelect}
name={`${item.name} — ${t('in_person_proofing.body.location.post_office')}`}
streetAddress={item.streetAddress}
selectId={item.id}
formattedCityStateZip={item.formattedCityStateZip}
weekdayHours={item.weekdayHours}
saturdayHours={item.saturdayHours}
sundayHours={item.sundayHours}
/>
));
locationsContent = (
<LocationCollection>
{locationData.map((item, index) => (
<LocationCollectionItem
key={`${index}-${item.name}`}
handleSelect={handleLocationSelect}
name={`${item.name} — ${t('in_person_proofing.body.location.post_office')}`}
streetAddress={item.streetAddress}
selectId={item.id}
formattedCityStateZip={item.formattedCityStateZip}
weekdayHours={item.weekdayHours}
saturdayHours={item.saturdayHours}
sundayHours={item.sundayHours}
/>
))}
</LocationCollection>
);
}

return (
<>
<PageHeading>{t('in_person_proofing.headings.location')}</PageHeading>

<p>{t('in_person_proofing.body.location.location_step_about')}</p>
<LocationCollection>{locationItems}</LocationCollection>
{locationsContent}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change here fixes issue where previously we were rendering invalid content inside the LocationCollection's <ul>:

Permitted content | Zero or more <li><script> and <template> elements.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul

<BackButton onClick={toPreviousStep} />
</>
);
Expand Down