-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eudr - suppliers breakdown foundation
- Loading branch information
1 parent
dbcfb87
commit a86b72c
Showing
29 changed files
with
1,234 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://ui.shadcn.com/schema.json", | ||
"style": "default", | ||
"rsc": false, | ||
"tsx": true, | ||
"tailwind": { | ||
"config": "tailwind.config.ts", | ||
"css": "src/styles/globals.css", | ||
"baseColor": "slate", | ||
"cssVariables": true, | ||
"prefix": "" | ||
}, | ||
"aliases": { | ||
"components": "@/components", | ||
"utils": "@/lib/utils" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible'; | ||
|
||
const Collapsible = CollapsiblePrimitive.Root; | ||
|
||
const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger; | ||
|
||
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent; | ||
|
||
export { Collapsible, CollapsibleTrigger, CollapsibleContent }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as React from 'react'; | ||
import * as LabelPrimitive from '@radix-ui/react-label'; | ||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
const labelVariants = cva( | ||
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', | ||
); | ||
|
||
const Label = React.forwardRef< | ||
React.ElementRef<typeof LabelPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants> | ||
>(({ className, ...props }, ref) => ( | ||
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} /> | ||
)); | ||
Label.displayName = LabelPrimitive.Root.displayName; | ||
|
||
export { Label }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from 'react'; | ||
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group'; | ||
import { Circle } from 'lucide-react'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
const RadioGroup = React.forwardRef< | ||
React.ElementRef<typeof RadioGroupPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root> | ||
>(({ className, ...props }, ref) => { | ||
return <RadioGroupPrimitive.Root className={cn('grid gap-2', className)} {...props} ref={ref} />; | ||
}); | ||
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName; | ||
|
||
const RadioGroupItem = React.forwardRef< | ||
React.ElementRef<typeof RadioGroupPrimitive.Item>, | ||
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item> | ||
>(({ className, ...props }, ref) => { | ||
return ( | ||
<RadioGroupPrimitive.Item | ||
ref={ref} | ||
className={cn( | ||
'aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<RadioGroupPrimitive.Indicator className="flex items-center justify-center"> | ||
<Circle className="h-2.5 w-2.5 fill-current text-current" /> | ||
</RadioGroupPrimitive.Indicator> | ||
</RadioGroupPrimitive.Item> | ||
); | ||
}); | ||
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName; | ||
|
||
export { RadioGroup, RadioGroupItem }; |
32 changes: 32 additions & 0 deletions
32
client/src/containers/analysis-eudr/category-list/breakdown/breakdown-item/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { formatPercentage } from '@/utils/number-format'; | ||
|
||
const BreakdownItem = ({ | ||
name, | ||
color, | ||
icon, | ||
value, | ||
}: { | ||
name: string; | ||
color: string; | ||
icon: string; | ||
value: number; | ||
}): JSX.Element => { | ||
return ( | ||
<div className="flex items-center justify-between"> | ||
<div className="flex items-center"> | ||
<div className="mr-2 h-2 w-2 rounded-full bg-[#4AB7F3]" /> | ||
<span>{name}</span> | ||
</div> | ||
<div className="shrink-0 grow-0"> | ||
<div className="text-center"> | ||
{formatPercentage(value)} <span className="text-xs">of suppliers</span> | ||
</div> | ||
<div className="h-[2px] w-[340px] bg-gray-200"> | ||
<div className={`h-[2px] ${color}`} style={{ width: formatPercentage(value) }} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BreakdownItem; |
16 changes: 16 additions & 0 deletions
16
...c/containers/analysis-eudr/category-list/breakdown/deforestation-free-suppliers/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const SAMPLE_DATA = { | ||
byMaterial: [ | ||
{ name: 'Supplier 1', value: 100 }, | ||
{ name: 'Supplier 1', value: 100 }, | ||
], | ||
byOrigin: [ | ||
{ name: 'Supplier 1', value: 100, iso3: 'ITA' }, | ||
{ name: 'Supplier 1', value: 100, iso3: 'ITA' }, | ||
], | ||
}; | ||
|
||
const DeforestationFreeSuppliersBreakdown = () => { | ||
return <div>DeforestationFreeSuppliersBreakdown</div>; | ||
}; | ||
|
||
export default DeforestationFreeSuppliersBreakdown; |
5 changes: 5 additions & 0 deletions
5
...iners/analysis-eudr/category-list/breakdown/suppliers-with-deforestation-alerts/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const SuppliersWithDeforestationAlertsBreakdown = () => { | ||
return <div>SuppliersWithDeforestationAlertsBreakdown</div>; | ||
}; | ||
|
||
export default SuppliersWithDeforestationAlertsBreakdown; |
5 changes: 5 additions & 0 deletions
5
...ontainers/analysis-eudr/category-list/breakdown/suppliers-with-no-location-data/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const SuppliersWithNoLocationDataBreakdown = () => { | ||
return <div>SuppliersWithNoLocationData</div>; | ||
}; | ||
|
||
export default SuppliersWithNoLocationDataBreakdown; |
101 changes: 101 additions & 0 deletions
101
client/src/containers/analysis-eudr/category-list/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { useState } from 'react'; | ||
|
||
import DeforestationFreeSuppliersBreakdown from './breakdown/deforestation-free-suppliers'; | ||
import SuppliersWithDeforestationAlertsBreakdown from './breakdown/suppliers-with-deforestation-alerts'; | ||
import SuppliersWithNoLocationDataBreakdown from './breakdown/suppliers-with-no-location-data'; | ||
|
||
import { Button } from '@/components/button'; | ||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; | ||
import { formatPercentage } from '@/utils/number-format'; | ||
|
||
const CATEGORIES = [ | ||
{ | ||
name: 'Deforestation-free suppliers', | ||
slug: 'deforestation-free-suppliers', | ||
color: 'bg-[#4AB7F3]', | ||
// todo move this value field to the component | ||
value: 0.3, | ||
}, | ||
{ | ||
name: 'Suppliers with deforestation alerts', | ||
slug: 'suppliers-with-deforestation-alerts', | ||
color: 'bg-[#FFC038]', | ||
// todo move this value field to the component | ||
value: 0.6, | ||
}, | ||
{ | ||
name: 'Suppliers with no location data', | ||
slug: 'suppliers-with-no-location-data', | ||
color: 'bg-[#8460FF]', | ||
// todo move this value field to the component | ||
value: 0.1, | ||
}, | ||
] as const; | ||
|
||
type CategoryState = Record<(typeof CATEGORIES)[number]['slug'], boolean>; | ||
|
||
export const CategoryList = (): JSX.Element => { | ||
const [categories, toggleCategory] = useState<CategoryState>( | ||
CATEGORIES.reduce( | ||
(acc, category) => ({ | ||
...acc, | ||
[category.slug]: false, | ||
}), | ||
{} as CategoryState, | ||
), | ||
); | ||
const categoriesWithValues = CATEGORIES.map((category) => ({ | ||
...category, | ||
// todo: calculate value field here | ||
})); | ||
|
||
return ( | ||
<> | ||
{categoriesWithValues.map((category) => ( | ||
<Collapsible | ||
key={category.slug} | ||
className="rounded-xl bg-gray-50 p-5" | ||
onOpenChange={() => { | ||
toggleCategory((prev) => ({ | ||
...prev, | ||
[category.slug]: !prev[category.slug], | ||
})); | ||
}} | ||
> | ||
<div className="flex w-full items-center space-x-6"> | ||
<div className="flex-1 text-left">{category.name}</div> | ||
<div className="shrink-0 grow-0"> | ||
<div className="text-center"> | ||
{formatPercentage(category.value)} <span className="text-xs">of suppliers</span> | ||
</div> | ||
<div className="h-[2px] w-[340px] bg-gray-200"> | ||
<div | ||
className={`h-[2px] ${category.color}`} | ||
style={{ width: formatPercentage(category.value) }} | ||
/> | ||
</div> | ||
</div> | ||
<CollapsibleTrigger asChild> | ||
<Button type="button" size="xs" variant="white"> | ||
{categories[category.slug] ? 'Close details' : 'View details'} | ||
</Button> | ||
</CollapsibleTrigger> | ||
</div> | ||
<CollapsibleContent> | ||
{category.slug === 'deforestation-free-suppliers' && ( | ||
<DeforestationFreeSuppliersBreakdown /> | ||
)} | ||
{category.slug === 'suppliers-with-deforestation-alerts' && ( | ||
<SuppliersWithDeforestationAlertsBreakdown /> | ||
)} | ||
{category.slug === 'suppliers-with-no-location-data' && ( | ||
<SuppliersWithNoLocationDataBreakdown /> | ||
)} | ||
</CollapsibleContent> | ||
</Collapsible> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default CategoryList; |
Oops, something went wrong.