-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
view shelter 2 (DEV-1079) #781
Changes from all commits
ec3f9c8
f99eda6
c81527a
ee190fd
32c9b01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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": {} | ||
} | ||
] | ||
} |
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). |
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', | ||
}; |
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" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib'; |
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} />; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Button as default } from './Button'; |
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> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Card as default } from './Card'; |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just FYI: to allow to allow adding |
||
|
||
return <div className={pillClass}>{label}</div>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Pill as default } from './Pill'; |
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> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { PillContainer as default } from './PillContainer'; |
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'; |
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" | ||
} | ||
] | ||
} |
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"] | ||
} |
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.
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> | ||
); | ||
} |
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 ( | ||||||
tglaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
<Card title="Entry Requirements"> | ||||||
<div className="flex flex-col gap-2"> | ||||||
{shelter.entryRequirements.map((requirement, idx) => { | ||||||
if (!requirement.name) return null; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Use block braces for ifs, whiles, etc. (
Suggested change
ExplanationIt is recommended to always use braces and create explicit statement blocks.Using the allowed syntax to just write a single statement can lead to very confusing |
||||||
return ( | ||||||
<div key={idx}> | ||||||
{enumDisplayEntryRequirementChoices[requirement.name]} | ||||||
</div> | ||||||
); | ||||||
})} | ||||||
{shelter.entryInfo && ( | ||||||
<div | ||||||
className="flex gap-1" | ||||||
dangerouslySetInnerHTML={{ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Avoid using dangerouslySetInnerHTML with string concatenation as it poses security risks Consider using regular JSX with template literals instead, like: Entry Info: {shelter?.entryInfo}
|
||||||
__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={ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider simplifying the data transformation using filter and map instead of reduce for improved readability. The data transformation can be simplified while maintaining all safety checks. Using filter() and map() makes the intent clearer than reduce() here since we're transforming data rather than accumulating it. data={
shelter?.generalServices
?.filter(service => service.name && enumDisplayGeneralServiceChoices[service.name])
.map(service => enumDisplayGeneralServiceChoices[service.name]) ?? []
} This maintains all null checks while being more direct about the data flow: first filter out invalid services, then transform the remaining ones. |
||||||
shelter.generalServices?.reduce<string[]>((acc, service) => { | ||||||
if (service.name) { | ||||||
const displayName = | ||||||
enumDisplayGeneralServiceChoices[service.name]; | ||||||
if (displayName) acc.push(displayName); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Use block braces for ifs, whiles, etc. (
Suggested change
ExplanationIt is recommended to always use braces and create explicit statement blocks.Using the allowed syntax to just write a single statement can lead to very confusing |
||||||
} | ||||||
return acc; | ||||||
}, []) || [] | ||||||
} | ||||||
/> | ||||||
</div> | ||||||
</> | ||||||
); | ||||||
} |
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.
the color
success-90
is only defined in the context ofshelter-web
. that's ok for today, but we may need add global tailwind config file in libs somwhere. for now maybe just leave a TODO comment?also, should
px-4 py-1
go withbaseClasses
?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.
paddings no because if border comes the size will be different
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.
aaah ok.
if a different variant can have a border, then another way is to include border in baseClasses (with same color as background), and then just override the border-color. but not necessary