Based on the requirements and clarifications, here are the core classes, functions, and methods that will be necessary:
-
NutritionFactsLabel
React Component: This is the main component that will render the Nutrition Facts Label. It will accept avariant
prop to determine the type of label to render. -
NutritionFacts
Interface: This will define the shape of the data that theNutritionFactsLabel
component expects. -
StandardLabel
Component: This component will render the standard variant of the Nutrition Facts Label. -
build
npm script: This script will be responsible for building the library. -
test
npm script: This script will be responsible for running tests. -
publish
npm script: This script will be responsible for publishing the library to npm.
Assumptions:
-
The
NutritionFactsLabel
component will accept adata
prop of typeNutritionFacts
which will contain the nutrition facts to be displayed. -
The
variant
prop will be a string and will default to 'standard' if not provided. -
The
build
script will use Rollup to create a CommonJS, ESM, and UMD build. -
The
test
script will use Jest for testing. -
The
publish
script will use thenpm publish
command. -
Functional purity in this context means that the components and functions should not have side effects and should always produce the same output given the same input.
-
The project will follow best practices for TypeScript and React development, including using functional components, hooks, and TypeScript interfaces for props.
Now, let's move on to the implementation of each file.