Skip to content

Commit

Permalink
view shelter 2 (DEV-1079) (#781)
Browse files Browse the repository at this point in the history
* generated types

* react components, shelter ui half

* updates

---------

Co-authored-by: Tom Glaz <tgmessages@gmail.com>
  • Loading branch information
Davit-BetterAngels and tglaz authored Dec 17, 2024
1 parent 3897ba9 commit 78ee5fd
Show file tree
Hide file tree
Showing 35 changed files with 608 additions and 18 deletions.
3 changes: 3 additions & 0 deletions apps/shelter-web/src/assets/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
--color-neutral-70: #a8aeb8;
--color-neutral-90: #d3d9e3;
--color-neutral-98: #e8ecf2;
--color-neutral-99: #f4f6fd;
--color-success-30: #007934;
--color-success-90: #ddf8e8;
}

* {
Expand Down
3 changes: 3 additions & 0 deletions apps/shelter-web/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = {
'neutral-70': 'var(--color-neutral-70)',
'neutral-90': 'var(--color-neutral-90)',
'neutral-98': 'var(--color-neutral-98)',
'neutral-99': 'var(--color-neutral-99)',
'success-30': 'var(--color-success-30)',
'success-90': 'var(--color-success-90)',
},
},
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions libs/react/components/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/react/components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# react-components

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test react-components` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions libs/react/components/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'react-components',
preset: '../../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/react/components',
};
16 changes: 16 additions & 0 deletions libs/react/components/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "react-components",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/react/components/src",
"projectType": "library",
"tags": [],
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/react/components/jest.config.ts"
}
}
}
}
1 change: 1 addition & 0 deletions libs/react/components/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib';
42 changes: 42 additions & 0 deletions libs/react/components/src/lib/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import clsx from 'clsx';
import { ButtonHTMLAttributes } from 'react';

interface IButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
/**
* The size of the button. Determines padding and font size.
* - `sm`: 26px.
* - `md`: Medium size (default).
* - `lg`: Large size.
*/
size?: 'sm' | 'md' | 'lg';
/**
* The variant of the button. Determines background and text color.
* - `primary`: primary-20 background, white text.
* - `secondary`: neutral-99 background, primary-20 text.
*/
variant?: 'primary' | 'secondary';
}

export function Button(props: IButtonProps) {
const { size = 'md', variant = 'primary', className, ...rest } = props;

const sizeClasses = {
sm: 'h-[26px] px-2 text-sm',
md: 'h-[32px] px-4 text-base',
lg: 'h-[40px] px-6 text-lg',
};

const variantClasses = {
primary: 'bg-primary-20 text-white',
secondary: 'bg-neutral-99 text-primary-20',
};

const buttonClass = clsx(
className,
'font-semibold text-sm focus:outline-none rounded-lg',
sizeClasses[size],
variantClasses[variant]
);

return <button className={buttonClass} {...rest} />;
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/Button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Button as default } from './Button';
25 changes: 25 additions & 0 deletions libs/react/components/src/lib/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import clsx from 'clsx';
import { ReactNode } from 'react';

interface ICardProps {
children: ReactNode;
px?: 'px-0' | 'px-6';
pb?: 'pb-0' | 'pb-6';
title?: string;
className?: string;
}

export function Card(props: ICardProps) {
const { children, px = 'px-6', title, pb = 'pb-6', className } = props;

const baseClasses = 'border-neutral-90 border pt-6 rounded-lg bg-white';

const pxClasses = clsx(baseClasses, px, pb, className);

return (
<div className={pxClasses}>
{title && <h3 className="font-semibold mb-2">{title}</h3>}
<div className="text-sm">{children}</div>
</div>
);
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/Card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Card as default } from './Card';
26 changes: 26 additions & 0 deletions libs/react/components/src/lib/Pill/Pill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import clsx from 'clsx';

interface IPillProps {
/**
* The type of pill. Determines background and border styles.
* - `primary`: Primary-themed pill.
* - `success`: Success-themed pill (default).
*/
type?: 'success';
label: string;
className?: string;
}

export function Pill(props: IPillProps) {
const { label, type = 'success', className } = props;

const baseClasses = 'rounded-[20px] inline-flex items-center justify-center';

const typeClasses = {
success: 'bg-success-90 text-primary-20 px-4 py-1',
};

const pillClass = clsx(baseClasses, typeClasses[type], className);

return <div className={pillClass}>{label}</div>;
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/Pill/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Pill as default } from './Pill';
40 changes: 40 additions & 0 deletions libs/react/components/src/lib/PillContainer/PillContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useState } from 'react';
import Pill from '../Pill';

interface IPillContainerProps {
data: string[];
type?: 'success';
maxVisible: number;
}

export function PillContainer({
data,
type = 'success',
maxVisible,
}: IPillContainerProps) {
const [showAll, setShowAll] = useState(false);
const servicesToDisplay = showAll ? data : data.slice(0, maxVisible);

return (
<div className="flex flex-col">
<div className="flex flex-wrap gap-1">
{servicesToDisplay.map((item, idx) => (
<Pill type={type} label={item} key={idx} />
))}
</div>

{data.length > maxVisible && (
<button
className="mt-3 ml-auto mr-auto"
onClick={() => setShowAll(!showAll)}
aria-label={showAll ? 'Show fewer items' : 'Show all items'}
>
<p className="text-xs font-semibold">
{showAll ? `View Less` : `View All (+${data.length - maxVisible})`}
</p>
{/* <ChevronLeftIcon className={clsx('chevron-icon', { rotated: showAll })} /> */}
</button>
)}
</div>
);
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/PillContainer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PillContainer as default } from './PillContainer';
4 changes: 4 additions & 0 deletions libs/react/components/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default as Button } from './Button';
export { default as Card } from './Card';
export { default as Pill } from './Pill';
export { default as PillContainer } from './PillContainer';
24 changes: 24 additions & 0 deletions libs/react/components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"esModuleInterop": true,
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/react/components/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
14 changes: 14 additions & 0 deletions libs/react/components/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions libs/react/shelter/src/lib/pages/shelter/Actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default function Actions() {
return (
<div className="flex items-center py-4 justify-between text-xs px-11 border-neutral-90 border-t border-b mt-4 -mx-4">
<div>
<span>Call</span>
</div>
<div>
<span>Directions</span>
</div>
<div>
<span>Share</span>
</div>
</div>
);
}
48 changes: 48 additions & 0 deletions libs/react/shelter/src/lib/pages/shelter/EntryRequirements.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Card } from '@monorepo/react/components';
import { enumDisplayEntryRequirementChoices } from '../../static';
import { ViewShelterQuery } from './__generated__/shelter.generated';

export default function EntryRequirements({
shelter,
}: {
shelter: ViewShelterQuery['shelter'];
}) {
return (
<Card title="Entry Requirements">
<div className="flex flex-col gap-2">
{shelter.entryRequirements.map((requirement, idx) => {
if (!requirement.name) return null;
return (
<div key={idx}>
{enumDisplayEntryRequirementChoices[requirement.name]}
</div>
);
})}
{shelter.entryInfo && (
<div
className="flex gap-1"
dangerouslySetInnerHTML={{
__html: 'Entry Info: ' + shelter?.entryInfo,
}}
/>
)}
{shelter.bedFees && (
<div
className="flex gap-1"
dangerouslySetInnerHTML={{
__html: 'Bed Fees: ' + shelter?.bedFees,
}}
/>
)}
{shelter.programFees && (
<div
className="flex gap-1"
dangerouslySetInnerHTML={{
__html: 'Program Fees: ' + shelter?.programFees,
}}
/>
)}
</div>
</Card>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PillContainer } from '@monorepo/react/components';
import { enumDisplayGeneralServiceChoices } from '../../../static';
import { ViewShelterQuery } from '../__generated__/shelter.generated';

export default function GeneralServices({
shelter,
}: {
shelter: ViewShelterQuery['shelter'];
}) {
return (
<>
<div>
<p>Available General Services</p>
</div>
<div className="pb-6">
<PillContainer
maxVisible={5}
data={
shelter.generalServices?.reduce<string[]>((acc, service) => {
if (service.name) {
const displayName =
enumDisplayGeneralServiceChoices[service.name];
if (displayName) acc.push(displayName);
}
return acc;
}, []) || []
}
/>
</div>
</>
);
}
Loading

0 comments on commit 78ee5fd

Please sign in to comment.