-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
987 additions
and
2,172 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
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
File renamed without changes.
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,98 @@ | ||
<p> | ||
<img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=cookies" alt="Solid Primitives cookies"> | ||
</p> | ||
|
||
# @solid-primitives/cookies | ||
|
||
[![turborepo](https://img.shields.io/badge/built%20with-turborepo-cc00ff.svg?style=for-the-badge&logo=turborepo)](https://turborepo.org/) | ||
[![size](https://img.shields.io/bundlephobia/minzip/@solid-primitives/cookies?style=for-the-badge&label=size)](https://bundlephobia.com/package/@solid-primitives/cookies) | ||
[![version](https://img.shields.io/npm/v/@solid-primitives/cookies?style=for-the-badge)](https://www.npmjs.com/package/@solid-primitives/cookies) | ||
[![stage](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fraw.githubusercontent.com%2Fsolidjs-community%2Fsolid-primitives%2Fmain%2Fassets%2Fbadges%2Fstage-0.json)](https://github.com/solidjs-community/solid-primitives#contribution-process) | ||
|
||
A set of primitives for handling cookies in solid | ||
|
||
- [`createServerCookie`](#createservercookie) - Provides a getter and setter for a reactive cookie, which works isomorphically. | ||
- [`createUserTheme`](#createusertheme) - Creates a Server Cookie providing a type safe way to store a theme and access it on the server or client. | ||
- [`getCookiesString`](#getCookiesString) - A primitive that allows for the cookie string to be accessed isomorphically on the client, or on the server | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @solid-primitives/cookies | ||
# or | ||
yarn add @solid-primitives/cookies | ||
# or | ||
pnpm add @solid-primitives/cookies | ||
``` | ||
|
||
## How to use it | ||
|
||
## `createServerCookie` | ||
|
||
A primitive for creating a cookie that can be accessed isomorphically on the client, or the server. | ||
|
||
```ts | ||
import { createServerCookie } from "@solid-primitives/cookies"; | ||
|
||
const [cookie, setCookie] = createServerCookie("cookieName"); | ||
|
||
cookie(); // => string | undefined | ||
``` | ||
|
||
### Custom serialization | ||
|
||
Custom cookie serializers and deserializers can also be implemented | ||
|
||
```ts | ||
import { createServerCookie } from "@solid-primitives/cookies"; | ||
|
||
const [serverCookie, setServerCookie] = createServerCookie("coolCookie", { | ||
deserialize: str => (str ? str.split(" ") : []), // Deserializes cookie into a string[] | ||
serialize: val => (val ? val.join(" ") : ""), // serializes the value back into a string | ||
}); | ||
|
||
serverCookie(); // => string[] | ||
``` | ||
|
||
## `createUserTheme` | ||
|
||
Composes `createServerCookie` to provide a type safe way to store a theme and access it on the server or client. | ||
|
||
```ts | ||
import { createUserTheme } from "@solid-primitives/cookies"; | ||
|
||
const [theme, setTheme] = createUserTheme("cookieName"); | ||
|
||
theme(); // => "light" | "dark" | undefined | ||
|
||
// with default value | ||
const [theme, setTheme] = createUserTheme("cookieName", { | ||
defaultValue: "light", | ||
}); | ||
|
||
theme(); // => "light" | "dark" | ||
``` | ||
|
||
## `getCookiesString` | ||
|
||
A primitive that allows for the cookie string to be accessed isomorphically on the client, or on the server. | ||
Uses `getRequestEvent` on the server and `document.cookie` on the client. | ||
|
||
```ts | ||
import { getCookiesString, parseCookie } from "@solid-primitives/cookies"; | ||
|
||
const string = getCookiesString(); | ||
const cookie = parseCookie(string, "cookie_name"); | ||
``` | ||
|
||
## Examples | ||
|
||
PRs welcome :) | ||
|
||
## Demo | ||
|
||
You can view a demo of this primitive here: <https://codesandbox.io/p/sandbox/amazing-easley-wqk38i?file=%2Fsrc%2Fcookies_primitive%2Findex.ts%3A36%2C20> | ||
|
||
## Changelog | ||
|
||
See [CHANGELOG.md](./CHANGELOG.md) |
9 changes: 5 additions & 4 deletions
9
packages/start/dev/index.tsx → packages/cookies/dev/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
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
{ | ||
"name": "@solid-primitives/start", | ||
"version": "0.0.4", | ||
"description": "A set of primitives for Solid Start", | ||
"author": "Thomas", | ||
"name": "@solid-primitives/cookies", | ||
"version": "0.0.1", | ||
"description": "A set of primitives for handling cookies in solid", | ||
"author": "Thomas Beer (https://github.com/Tommypop2)", | ||
"contributors": [ | ||
"Damian Tarnawski <[email protected]>" | ||
"Damian Tarnawski <[email protected]>", | ||
"Seth Murphy (https://github.com/eagerestwolf)" | ||
], | ||
"license": "MIT", | ||
"homepage": "https://primitives.solidjs.community/package/start", | ||
"homepage": "https://primitives.solidjs.community/package/cookies", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/solidjs-community/solid-primitives.git" | ||
|
@@ -16,18 +17,18 @@ | |
"url": "https://github.com/solidjs-community/solid-primitives/issues" | ||
}, | ||
"primitive": { | ||
"name": "start", | ||
"name": "cookies", | ||
"stage": 0, | ||
"list": [ | ||
"createServerCookie", | ||
"createUserTheme" | ||
"createUserTheme", | ||
"getCookiesString" | ||
], | ||
"category": "Solid Start" | ||
"category": "Network" | ||
}, | ||
"keywords": [ | ||
"solid", | ||
"primitives", | ||
"solid-start", | ||
"ssr" | ||
], | ||
"private": false, | ||
|
@@ -59,11 +60,9 @@ | |
"test:ssr": "pnpm run vitest --mode ssr" | ||
}, | ||
"peerDependencies": { | ||
"solid-js": "^1.6.12", | ||
"solid-start": ">=0.2.26" | ||
"solid-js": "^1.8.18" | ||
}, | ||
"devDependencies": { | ||
"solid-js": "^1.8.7", | ||
"solid-start": "^0.3.10" | ||
"solid-js": "^1.8.18" | ||
} | ||
} |
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
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@solid-primitives/date", | ||
"version": "2.0.23", | ||
"version": "2.0.24", | ||
"description": "Collection of reactive primitives and utility functions, providing easier ways to deal with dates in SolidJS", | ||
"author": "Damian Tarnawski @thetarnav <[email protected]>", | ||
"license": "MIT", | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@solid-primitives/deep", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"description": "Primitives for tracking and observing nested reactive objects in Solid.", | ||
"author": "Samuel Burbano <[email protected]>", | ||
"contributors": [ | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@solid-primitives/immutable", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Primitive for rectifying immutable values and dealing with immutability in Solid.", | ||
"author": "Damian Tarnawski <[email protected]>", | ||
"contributors": [], | ||
|
Oops, something went wrong.