linkedin / linkedin/css-blocks

TypeScript type checking for css-blocks as imported modules.

Open
#29 1 comment 3 reactions 0 assignees View on GitHub
@css-blocks/core enhancement
Dominant language
TypeScript
Stars
6.3k
Forks
154
PR merge metrics
No merged PRs in 30d

Description

Each CSS block file can be represented as a collection of TypeScript classes.

```css
.root { block-name: a-css-block; }
[state|a-block-state] {}
.a-thing {}
.a-thing[state|active] {}
.a-thing[state|my-theme=red] {}
.a-thing[state|my-theme=blue] {}
```

```ts
// these would be defined statically for all blocks and imported
type OptimizedClassNames = string[];
export interface BlockClass {
}
export type BooleanBlockState = () => OptimizedClassNames;
export type ExclusiveBlockState = (value: string) => OptimizedClassNames;
export type BlockState = BooleanBlockState | ExclusiveBlockState;
// type for this block
export class ACssBlock implements BlockClass {
root: this;
active: () => OptimizedClassNames;
"a-thing": ACssBlock.AThingClass;
[name: string]: BlockClass | BlockState;
}
export namespace ACssBlock {
export class AThingClass implements BlockClass {
[name: string]: BlockState;
"my-theme": (value: "red" | "blue") => OptimizedClassNames;
}
}
// usage example:
function foo(a: ACssBlock): OptimizedClassNames {
return a["a-thing"]["my-theme"]("red");
}
```

TODO:

- [ ] Further examples of block interfaces and inheritance are needed.
- [ ] Figure out how to create indexed types with only a limited set of indexed names.

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by reviewing the proposed CSS and TypeScript examples, then clarify the missing block-interface and inheritance cases and the requirements for restricting indexed names; done criteria are not yet fully defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.