@guardian/src-foundations

中文文档
3.13.0发布于 2022/01/18Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 5251

The Guardian's foundations are the atoms from which all our visual design is built. They are intended for use with a CSS-in-JS library such as Emotion.

此软件包已被标记为弃用

This package has been replaced by @guardian/source-foundations.

原始使用文档
文档目录9 节
  1. Install
  2. Use
  3. Palette
  4. Typography
  5. Media queries
  6. Size
  7. Visually Hidden
  8. Focus Halo
  9. Description Id

Foundations

The Guardian's foundations are the atoms from which all our visual design is built. They are intended for use with a CSS-in-JS library such as Emotion.

Install

$ yarn add @guardian/src-foundations

Use

Palette

import { background } from '@guardian/src-foundations/palette';

const backgroundColor = css`
    background-color: ${background.primary};
`;

Typography

import { headline, body, textSans } from '@guardian/src-foundations/typography';

const h1 = css`
    ${headline.large({ fontWeight: 'bold' })};
`;

const p = css`
    ${body.main()};
`;

const copyright = css`
    ${textSans.xsmall()};
`;

Media queries

import { from, until, between } from '@guardian/src-foundations/mq';

const styles = css`
    padding: 0 10px;

    ${from.mobileLandscape} {
        padding: 0 20px;
    }

    ${between.phablet.and.desktop} {
        padding: 0 32px;
    }

    ${until.wide} {
        padding: 0 40px;
    }
`;

Size

import { width, height } from '@guardian/src-foundations/size';

const checkbox = css`
    width: ${width.inputXsmall}px;
    height: ${height.inputXsmall}px;
`;

Visually Hidden

For elements that should not appear to sighted users, but are useful to assistive technology users.

import { visuallyHidden } from '@guardian/src-foundations/accessibility';

const label = css`
    ${visuallyHidden};
`;

Focus Halo

This mixin provides a clear focus state for elements that may receive keyboard focus.

import { focusHalo } from '@guardian/src-foundations/accessibility';

const input = css`
    ${focusHalo};
    width: 200px;
    height: 44px;
`;

Description Id

A function that takes the ID of an element and generates a new ID. This should be set as the ID of an element that describes the first element. The generated ID should also be passed to the aria-describedby attribute on the first element.

import { descriptionId } from '@guardian/src-foundations/accessibility';

const Form = () => {
    const id = 'first_name';
    return (
        <form>
            <input id={id} type="text" aria-describedby={descriptionId(id)} />
            <p class="error" id={descriptionId(id)} />
        </form>
    );
};

版本与发布记录

@guardian/src-foundations 共发布 168 个版本,首次发布于 2019/08/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.13.0latest2022/01/184 年前
3.12.02021/11/095 年前
3.11.02021/11/055 年前
3.10.32021/11/035 年前
3.10.2-alpha.12021/10/195 年前
3.10.2-alpha.02021/10/195 年前

其他发布通道:next → 3.2.1-rc.5。

关于 @guardian/src-foundations 的常见问题

@guardian/src-foundations 是什么?

The Guardian's foundations are the atoms from which all our visual design is built. They are intended for use with a CSS-in-JS library such as Emotion.注意:该包已被作者标记为弃用——This package has been replaced by @guardian/source-foundations.

如何安装 @guardian/src-foundations?

在项目目录运行 npm install @guardian/src-foundations,或使用 pnpm add / yarn add / bun add。

@guardian/src-foundations 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@guardian/src-foundations 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@guardian/src-foundations 可以商用吗?

@guardian/src-foundations 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@guardian/src-foundations 的下载量有多少?

根据 npm 官方下载统计,@guardian/src-foundations 在 2026/10/17 – 2026/11/15 这 30 天内被下载 5,251 次,日均约 175 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@guardian/src-foundations 还在维护吗?

最新版本 3.13.0 发布于 2022/01/18(4 年前);至今共发布 168 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/08/07。作者已将其标记为弃用,新项目建议寻找替代方案。