Files
webstudio/apps/builder/app/shared/nano-states/breakpoints.ts
T
Oleg Isonen b2bf220ed6 chore: Rename all *Store to $store (#2747)
## Description

Pure renaming, nothing else.

## Code Review

- [ ] hi @TrySound , I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2024-01-09 13:32:51 +01:00

35 lines
954 B
TypeScript

import { atom, computed } from "nanostores";
import type { Breakpoint, Breakpoints } from "@webstudio-is/sdk";
import { isBaseBreakpoint } from "../breakpoints";
export const $breakpoints = atom<Breakpoints>(new Map());
export const $selectedBreakpointId = atom<undefined | Breakpoint["id"]>(
undefined
);
export const $selectedBreakpoint = computed(
[$breakpoints, $selectedBreakpointId],
(breakpoints, selectedBreakpointId) => {
const selectedBreakpoint =
selectedBreakpointId === undefined
? undefined
: breakpoints.get(selectedBreakpointId);
if (breakpoints.size === 0) {
return;
}
const breakpointsArray = Array.from(breakpoints.values());
return (
selectedBreakpoint ??
breakpointsArray.find(isBaseBreakpoint) ??
breakpointsArray[0] ??
undefined
);
}
);
export const $synchronizedBreakpoints = [
["selectedBreakpointId", $selectedBreakpointId],
] as const;