@cooperco/cooper-component-library 0.1.61 → 0.1.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,113 @@
1
- # Vue 3 + Vite
1
+ # Cooper Component Library
2
2
 
3
- This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
3
+ A Vue 3 component library built with TypeScript, Vite, and Tailwind CSS. Published as `@cooperco/cooper-component-library` and designed for integration with Contentful CMS via GraphQL.
4
+
5
+ ## Tech Stack
6
+
7
+ - **Vue 3.5+** - Composition API with `<script setup>`
8
+ - **TypeScript 5.3+** - Strict mode enabled
9
+ - **Tailwind CSS 3.4+** - Utility-first styling
10
+ - **Vite 5.2+** - Library build mode
11
+ - **Storybook 8.2+** - Component documentation
12
+ - **GraphQL** - Contentful CMS integration
13
+ - **pnpm** - Package manager
4
14
 
5
15
  ## Recommended IDE Setup
6
16
 
7
17
  - [VS Code](https://code.visualstudio.com/) + [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously Volar) and disable Vetur
8
18
 
9
- ### TODO issues
19
+ ## Development
20
+
21
+ ```bash
22
+ # Install dependencies
23
+ pnpm install
24
+
25
+ # Start Storybook dev server
26
+ pnpm run dev
27
+
28
+ # Run linter
29
+ pnpm run lint
30
+
31
+ # Fix linting issues
32
+ pnpm run lint:fix
33
+
34
+ # Type check
35
+ pnpm run check-types
36
+ ```
37
+
38
+ ## Testing Locally
39
+
40
+ To test the component library in a consuming project before publishing:
41
+
42
+ ```bash
43
+ # 1. Build and pack the library
44
+ pnpm run local-test
45
+ ```
46
+
47
+ This creates a `.tgz` file in the root directory (e.g., `cooperco-cooper-component-library-0.1.61.tgz`)
48
+
49
+ ```bash
50
+ # 2. In the consuming project, install the local package
51
+ pnpm add /path/to/cooperco-cooper-component-library-0.1.61.tgz
52
+ ```
53
+
54
+ This allows you to test changes locally before publishing to npm.
55
+
56
+ ## Building and Publishing
57
+
58
+ The build and publish process needs to happen manually when changes are merged to `main`:
59
+
60
+ ### Workflow
61
+
62
+ 1. **Merge to main** - Merge your feature branch to `main`
63
+ 2. **Patch version** - Update version number using `npm version patch` (or `minor`/`major`)
64
+ 3. **Publish** - Run `npm publish` to publish to npm registry
65
+ 4. **Push** - Push changes and tags to GitHub
66
+
67
+ ### Build Process
68
+
69
+ When you run `pnpm run build`, the following happens in order:
70
+
71
+ 1. **`build:types`** - Compiles Vue component TypeScript definitions
72
+ 2. **`build:cms`** - Compiles GraphQL queries for Contentful
73
+ 3. **`vite build`** - Builds the component library bundle
74
+
75
+ All build artifacts are output to the `dist/` directory.
76
+
77
+ ### Package Exports
78
+
79
+ The package exports multiple entry points:
80
+
81
+ - **Components:** `@cooperco/cooper-component-library` - Main component library
82
+ - **Styles:** `@cooperco/cooper-component-library/css/main.css` - Main styles
83
+ - **Theme:** `@cooperco/cooper-component-library/css/theme.css` - Theme variables
84
+ - **Queries:** `@cooperco/cooper-component-library/cms/contentful/graphql` - GraphQL queries
85
+
86
+ ## Project Structure
87
+
88
+ ```
89
+ ├── src/
90
+ │ ├── components/ # Vue components
91
+ │ │ ├── ComponentName/
92
+ │ │ │ ├── ComponentName.vue
93
+ │ │ │ └── ComponentName.ts
94
+ │ │ ├── components.ts # Component exports
95
+ │ │ └── types.ts # Type exports
96
+ │ ├── config/ # Configuration (color palettes, passthroughs)
97
+ │ └── utils/ # Utility functions
98
+ ├── cms/
99
+ │ └── contentful/
100
+ │ └── queries/ # GraphQL queries (see cms/contentful/queries/README.md)
101
+ ├── .storybook/ # Storybook configuration
102
+ │ └── components/ # Component stories
103
+ └── dist/ # Build output (generated)
104
+ ```
105
+
106
+ ## Documentation
107
+
108
+ - **Component Documentation:** Run `pnpm run dev` to view Storybook
109
+ - **GraphQL Queries:** See [cms/contentful/queries/README.md](cms/contentful/queries/README.md)
110
+
111
+ ## TODO Issues
10
112
 
11
- - There are many places where `class` is not recognized by Typescript. Examples are "start"/"end" in ContainerModule. This is because we are not defining `class` on the component types. Defining them explicitly overrides the default Attribute Inheritance behavior of Vue. Need to find a way to get around this
113
+ - There are many places where `class` is not recognized by TypeScript. Examples are "start"/"end" in ContainerModule. This is because we are not defining `class` on the component types. Defining them explicitly overrides the default Attribute Inheritance behavior of Vue. Need to find a way to get around this
@@ -1,42 +1,112 @@
1
- # Migrations
1
+ # GraphQL Queries
2
2
 
3
- ## Prerequisites
3
+ This directory contains GraphQL queries for fetching content from Contentful CMS.
4
4
 
5
- - Run `pnpm install`
6
- - Obtain a Contentful CMA token
7
- - Confirm and double check what space and environment you should be running these in
8
- - Run `pnpm exec contentful-cli-migrations --environment-id <your-env-name> --space-id <space-id> --management-token <CMA-TOKEN> --initialise` on environment if not already and update `.env`
5
+ ## Directory Structure
9
6
 
7
+ ```
8
+ cms/contentful/queries/
9
+ ├── index.ts # Barrel export file (manual updates required)
10
+ ├── fragments.ts # Shared GraphQL fragments
11
+ ├── *.query.ts # Individual component queries
12
+ └── README.md # This file
13
+ ```
10
14
 
11
- ## Helpful Docs
15
+ ## How Queries Are Exported
12
16
 
13
- - [Contentful Migration](https://github.com/contentful/contentful-migration)
14
- - [Contentful Migration Reference Docs](https://github.com/contentful/contentful-migration/blob/main/README.md#reference-documentation)
15
- - [Contentful Data Model](https://www.contentful.com/developers/docs/concepts/data-model/)
17
+ The query export system in this project is **semi-automatic**:
16
18
 
17
- ### Instructions
19
+ ### The Process
18
20
 
19
- - Create your migration file in the scripts folder with the following format: `0002-description.cjs`
20
- - Write your migrations
21
- - This should be with an up and a down function
22
- - The up function updates the model
23
- - The down function reversts your changes
24
- - Run your migration on a test environment with the following command: `pnpm exec contentful-cli-migrations --environment-id <your-env-name> --space-id <space-id> --management-token <CMA-TOKEN>`
25
- - Optional Flags:
26
- - `--rollback`: Rolls back one migration.
21
+ 1. **Individual Query Files** - Queries are defined in individual files with the pattern `*.query.ts`
22
+ - Example: `accordion.query.ts`, `carousel.query.ts`
27
23
 
28
- ### Gotchas
24
+ 2. **Manual Barrel Export** - Queries are re-exported through `index.ts`
25
+ - Uses wildcard exports: `export * from './accordion.query.js'`
26
+ - **Note:** Exports use `.js` extensions even though source files are `.ts` (ESM compatibility)
29
27
 
30
- - Currently the rollback may change the version counter even if the migration doesnt run.
31
- - for this just update the counter to the correct counter in contentful and rerun.
32
- - The migration may run and create a content type even if the whole migration doesnt run correctly.
33
- - To fix you will need to delete the content type and re-run
28
+ 3. **Package-Level Export** - The barrel export is exposed via `package.json`:
29
+ ```json
30
+ "./cms/contentful/graphql": {
31
+ "import": "./dist/cms/contentful/queries/index.js",
32
+ "types": "./dist/cms/contentful/queries/index.d.ts"
33
+ }
34
+ ```
34
35
 
35
- ### TODO
36
+ ## Creating a New Query
36
37
 
37
- - Fix rollback versioning
38
- - This flag should cause a rollback to that specific version, in this case 0001 `--version 0001`
39
- - It should be used with `--rollback`
40
- - It should update dthe versionTracker entry on successful rollback
41
- - Run migration error handling
42
- - runMigration is currently not working as expected and bumping the counter when the migration was aborted
38
+ ### Steps Required
39
+
40
+ 1. **Create Query File** - Add your query file: `yourComponent.query.ts`
41
+
42
+ 2. **Define Query** - Follow the established pattern:
43
+ ```typescript
44
+ import { gql } from 'graphql-tag'
45
+ import type { DocumentNode } from 'graphql'
46
+ import { someFragment } from './fragments.js' // If needed
47
+
48
+ export const getYourComponent: DocumentNode = gql`
49
+ ${someFragment} // Include fragments if needed
50
+ query yourComponentQuery($id: String!, $preview: Boolean = false) {
51
+ yourComponent(id: $id, preview: $preview) {
52
+ __typename
53
+ # Add your fields here
54
+ }
55
+ }
56
+ `
57
+ ```
58
+
59
+ 3. **Update Barrel Export** - **MANUALLY ADD** export to `index.ts`:
60
+ ```typescript
61
+ export * from './yourComponent.query.js'
62
+ ```
63
+ - Maintain alphabetical order for consistency
64
+ - Use `.js` extension (not `.ts`)
65
+
66
+ ### Query Naming Conventions
67
+
68
+ - **File Name:** `componentName.query.ts` (camelCase)
69
+ - **Export Name:** `getComponentName` (camelCase with `get` prefix)
70
+ - **Query Name:** `componentNameQuery` (camelCase with `Query` suffix)
71
+
72
+ ### Example
73
+
74
+ ```typescript
75
+ // accordion.query.ts
76
+ import { gql } from 'graphql-tag'
77
+ import type { DocumentNode } from 'graphql'
78
+ import { accordionItemFragment } from './fragments.js'
79
+
80
+ export const getAccordion: DocumentNode = gql`
81
+ ${accordionItemFragment}
82
+ query accordionQuery($id: String!, $preview: Boolean = false) {
83
+ accordion(id: $id, preview: $preview) {
84
+ __typename
85
+ headline
86
+ accordionType
87
+ loadMoreButtonTitle
88
+ startOpen
89
+ accordionItemCollection {
90
+ items {
91
+ ...accordionItemFragment
92
+ }
93
+ }
94
+ }
95
+ }
96
+ `
97
+ ```
98
+
99
+ ## Using Queries in Consumer Projects
100
+
101
+ Queries are consumed via the package export:
102
+
103
+ ```typescript
104
+ import { getAccordion, getCarousel } from '@cooperco/cooper-component-library/cms/contentful/graphql'
105
+ ```
106
+
107
+ ## Important Notes
108
+
109
+ - **Manual Export Required:** The system is NOT fully automatic - you MUST manually update `index.ts` when adding new queries
110
+ - **ESM Extensions:** Always use `.js` extensions in exports (even for `.ts` source files)
111
+ - **Preview Mode:** All queries support a `preview` parameter for Contentful preview API
112
+ - **Fragments:** Shared fragments are defined in `fragments.ts` and can be reused across queries
@@ -0,0 +1,112 @@
1
+ # GraphQL Queries
2
+
3
+ This directory contains GraphQL queries for fetching content from Contentful CMS.
4
+
5
+ ## Directory Structure
6
+
7
+ ```
8
+ cms/contentful/queries/
9
+ ├── index.ts # Barrel export file (manual updates required)
10
+ ├── fragments.ts # Shared GraphQL fragments
11
+ ├── *.query.ts # Individual component queries
12
+ └── README.md # This file
13
+ ```
14
+
15
+ ## How Queries Are Exported
16
+
17
+ The query export system in this project is **semi-automatic**:
18
+
19
+ ### The Process
20
+
21
+ 1. **Individual Query Files** - Queries are defined in individual files with the pattern `*.query.ts`
22
+ - Example: `accordion.query.ts`, `carousel.query.ts`
23
+
24
+ 2. **Manual Barrel Export** - Queries are re-exported through `index.ts`
25
+ - Uses wildcard exports: `export * from './accordion.query.js'`
26
+ - **Note:** Exports use `.js` extensions even though source files are `.ts` (ESM compatibility)
27
+
28
+ 3. **Package-Level Export** - The barrel export is exposed via `package.json`:
29
+ ```json
30
+ "./cms/contentful/graphql": {
31
+ "import": "./dist/cms/contentful/queries/index.js",
32
+ "types": "./dist/cms/contentful/queries/index.d.ts"
33
+ }
34
+ ```
35
+
36
+ ## Creating a New Query
37
+
38
+ ### Steps Required
39
+
40
+ 1. **Create Query File** - Add your query file: `yourComponent.query.ts`
41
+
42
+ 2. **Define Query** - Follow the established pattern:
43
+ ```typescript
44
+ import { gql } from 'graphql-tag'
45
+ import type { DocumentNode } from 'graphql'
46
+ import { someFragment } from './fragments.js' // If needed
47
+
48
+ export const getYourComponent: DocumentNode = gql`
49
+ ${someFragment} // Include fragments if needed
50
+ query yourComponentQuery($id: String!, $preview: Boolean = false) {
51
+ yourComponent(id: $id, preview: $preview) {
52
+ __typename
53
+ # Add your fields here
54
+ }
55
+ }
56
+ `
57
+ ```
58
+
59
+ 3. **Update Barrel Export** - **MANUALLY ADD** export to `index.ts`:
60
+ ```typescript
61
+ export * from './yourComponent.query.js'
62
+ ```
63
+ - Maintain alphabetical order for consistency
64
+ - Use `.js` extension (not `.ts`)
65
+
66
+ ### Query Naming Conventions
67
+
68
+ - **File Name:** `componentName.query.ts` (camelCase)
69
+ - **Export Name:** `getComponentName` (camelCase with `get` prefix)
70
+ - **Query Name:** `componentNameQuery` (camelCase with `Query` suffix)
71
+
72
+ ### Example
73
+
74
+ ```typescript
75
+ // accordion.query.ts
76
+ import { gql } from 'graphql-tag'
77
+ import type { DocumentNode } from 'graphql'
78
+ import { accordionItemFragment } from './fragments.js'
79
+
80
+ export const getAccordion: DocumentNode = gql`
81
+ ${accordionItemFragment}
82
+ query accordionQuery($id: String!, $preview: Boolean = false) {
83
+ accordion(id: $id, preview: $preview) {
84
+ __typename
85
+ headline
86
+ accordionType
87
+ loadMoreButtonTitle
88
+ startOpen
89
+ accordionItemCollection {
90
+ items {
91
+ ...accordionItemFragment
92
+ }
93
+ }
94
+ }
95
+ }
96
+ `
97
+ ```
98
+
99
+ ## Using Queries in Consumer Projects
100
+
101
+ Queries are consumed via the package export:
102
+
103
+ ```typescript
104
+ import { getAccordion, getCarousel } from '@cooperco/cooper-component-library/cms/contentful/graphql'
105
+ ```
106
+
107
+ ## Important Notes
108
+
109
+ - **Manual Export Required:** The system is NOT fully automatic - you MUST manually update `index.ts` when adding new queries
110
+ - **ESM Extensions:** Always use `.js` extensions in exports (even for `.ts` source files)
111
+ - **Preview Mode:** All queries support a `preview` parameter for Contentful preview API
112
+ - **Fragments:** Shared fragments are defined in `fragments.ts` and can be reused across queries
@@ -0,0 +1,112 @@
1
+ # GraphQL Queries
2
+
3
+ This directory contains GraphQL queries for fetching content from Contentful CMS.
4
+
5
+ ## Directory Structure
6
+
7
+ ```
8
+ cms/contentful/queries/
9
+ ├── index.ts # Barrel export file (manual updates required)
10
+ ├── fragments.ts # Shared GraphQL fragments
11
+ ├── *.query.ts # Individual component queries
12
+ └── README.md # This file
13
+ ```
14
+
15
+ ## How Queries Are Exported
16
+
17
+ The query export system in this project is **semi-automatic**:
18
+
19
+ ### The Process
20
+
21
+ 1. **Individual Query Files** - Queries are defined in individual files with the pattern `*.query.ts`
22
+ - Example: `accordion.query.ts`, `carousel.query.ts`
23
+
24
+ 2. **Manual Barrel Export** - Queries are re-exported through `index.ts`
25
+ - Uses wildcard exports: `export * from './accordion.query.js'`
26
+ - **Note:** Exports use `.js` extensions even though source files are `.ts` (ESM compatibility)
27
+
28
+ 3. **Package-Level Export** - The barrel export is exposed via `package.json`:
29
+ ```json
30
+ "./cms/contentful/graphql": {
31
+ "import": "./dist/cms/contentful/queries/index.js",
32
+ "types": "./dist/cms/contentful/queries/index.d.ts"
33
+ }
34
+ ```
35
+
36
+ ## Creating a New Query
37
+
38
+ ### Steps Required
39
+
40
+ 1. **Create Query File** - Add your query file: `yourComponent.query.ts`
41
+
42
+ 2. **Define Query** - Follow the established pattern:
43
+ ```typescript
44
+ import { gql } from 'graphql-tag'
45
+ import type { DocumentNode } from 'graphql'
46
+ import { someFragment } from './fragments.js' // If needed
47
+
48
+ export const getYourComponent: DocumentNode = gql`
49
+ ${someFragment} // Include fragments if needed
50
+ query yourComponentQuery($id: String!, $preview: Boolean = false) {
51
+ yourComponent(id: $id, preview: $preview) {
52
+ __typename
53
+ # Add your fields here
54
+ }
55
+ }
56
+ `
57
+ ```
58
+
59
+ 3. **Update Barrel Export** - **MANUALLY ADD** export to `index.ts`:
60
+ ```typescript
61
+ export * from './yourComponent.query.js'
62
+ ```
63
+ - Maintain alphabetical order for consistency
64
+ - Use `.js` extension (not `.ts`)
65
+
66
+ ### Query Naming Conventions
67
+
68
+ - **File Name:** `componentName.query.ts` (camelCase)
69
+ - **Export Name:** `getComponentName` (camelCase with `get` prefix)
70
+ - **Query Name:** `componentNameQuery` (camelCase with `Query` suffix)
71
+
72
+ ### Example
73
+
74
+ ```typescript
75
+ // accordion.query.ts
76
+ import { gql } from 'graphql-tag'
77
+ import type { DocumentNode } from 'graphql'
78
+ import { accordionItemFragment } from './fragments.js'
79
+
80
+ export const getAccordion: DocumentNode = gql`
81
+ ${accordionItemFragment}
82
+ query accordionQuery($id: String!, $preview: Boolean = false) {
83
+ accordion(id: $id, preview: $preview) {
84
+ __typename
85
+ headline
86
+ accordionType
87
+ loadMoreButtonTitle
88
+ startOpen
89
+ accordionItemCollection {
90
+ items {
91
+ ...accordionItemFragment
92
+ }
93
+ }
94
+ }
95
+ }
96
+ `
97
+ ```
98
+
99
+ ## Using Queries in Consumer Projects
100
+
101
+ Queries are consumed via the package export:
102
+
103
+ ```typescript
104
+ import { getAccordion, getCarousel } from '@cooperco/cooper-component-library/cms/contentful/graphql'
105
+ ```
106
+
107
+ ## Important Notes
108
+
109
+ - **Manual Export Required:** The system is NOT fully automatic - you MUST manually update `index.ts` when adding new queries
110
+ - **ESM Extensions:** Always use `.js` extensions in exports (even for `.ts` source files)
111
+ - **Preview Mode:** All queries support a `preview` parameter for Contentful preview API
112
+ - **Fragments:** Shared fragments are defined in `fragments.ts` and can be reused across queries