@ datagouv/ 组件
在本文档中,“用户”是使用 @datagouv/components (例如: cdata 或者说 udata-front-kit) (中文(简体) ). 关于一般项目的设置和开发,见 主要项目。 。 。 .
使用量
配置
@datagouv/components 页:1 阴道 装入配置的插件 .
import { datagouv } from '@datagouv/components-next'
app.use(datagouv, {
name: 'data.gouv.fr', // Name of the site in some texts
baseUrl: 'https://www.data.gouv.fr', // Used for redirects
apiBase: 'https://www.data.gouv.fr', // Used for API calls (could default to `baseUrl`?)
})
版式
用来使用 Toggletip 组件 <div id="tooltips" /> 在您的布局中.
特殊功能和组件( 只用于 Nuxt)
Nuxt是一个特殊的环境(包括服务器和浏览器),需要一些特殊的功能和组件才能工作.
import { TextClamp } from '#components'
import CdataLink from './components/CdataLink.vue'
import { datagouv, type UseFetchFunction } from '@datagouv/components-next'
const runtimeConfig = useRuntimeConfig()
app.vueApp.use(datagouv, {
// These are the same as above…
name: runtimeConfig.public.title,
baseUrl: runtimeConfig.public.baseUrl,
apiBase: runtimeConfig.public.apiBase,
devApiKey: runtimeConfig.public.devApiKey,
// ----------------------------------------
// --- Special functions and components ---
// Tell `@datagouv/components` to use `useFetch` from Nuxt instead of custom built-in.
customUseFetch: useFetch as UseFetchFunction,
// Nuxt doesn't like `TextClamp` in the server, provides the client only `TextClamp`
textClamp: TextClamp,
// The following properties allow to provide components specific to Nuxt.
// This `appLink` component will receive the raw link (without i18n prefix)
// and needs to add it.
appLink: CdataLink,
// The ClientOnly allow to disable SSR for some components.
clientOnly: ClientOnly,
})
支助科
@datagouv/components 正在使用 尾风CSS 还有一些 联邦 现在 用户需要提供DSFR的正确版本. 关于TailwindCSS,有两种模式:
- 如果用户正在使用 TailwindCSS, 它可以导入一个完整的 TailwindCSS 配置
@import "@datagouv/components-next/assets/main.css";,然后通过 TailwindCSS CLI 或 Vite 插件构建 CSS . - 如果用户没有使用TailwindCSS,它可以导入一个已经建好的CSS文件
@import '@datagouv/components-next/dist/components.css';。注意@dev,此文件应在将软件包发布到 PNPM 之前构建pnpm run css。详细情况请参见: 技术堆栈,参见主读取.
I18n 时
@datagouv/components 正在使用一些自定义功能提供国际化:
$t()模板内const { t } = useTranslation()联合来文<TranslationT keypath="xxx"></TranslationT>用于在文本中放置 HTML
Suspense
与 坚果,一些组件正在执行 HTTP 请求 setup 函数(Nuxt然后可以对这些请求进行SSSR:执行这些请求的服务器侧)。 这些组件需要用下列方式包裹: <Suspense> 包装( 你可以提供 #fallback) (中文(简体) ). 您可以将单个组件包入内部 <Suspense> 或将您的整个应用程序/推出包入 <Suspense>
<Suspense>
<ActivityList />
</Suspense>
发展
关于一般发展准则和贡献,见本报告附件 贡献部分 在主读取.
代码 Linting 和格式
此组件库同时使用ESLint和Pretier进行代码质量和格式化:
pnpm run lint # Lint and auto-fix ESLint issues
pnpm run format # Format code with Prettier
说明: 在提交贡献前确保运行这两个命令,以确保代码样式一致.
配置
您可以使用可混凝土配置 useComponentsConfig()。 。 。 .
import { useComponentsConfig } from '../main'
const config = useComponentsConfig()
特殊功能和组件( 只用于 Nuxt)
[尖叫声]
单位@datagouv/components我们无法直接使用一些功能和组件:
TextClamp组件useFetchNuxt 函数
要使用这些,需要从配置或者通过特殊的包装得到.
useFetch
import { useFetch } from '../functions/api'
const { data: allLicenses } = await useFetch<Array<License>>('/api/1/datasets/licenses/')
此包装将使用提供的 useFetch 函数来自 Nuxt 或自定义内置替换(在大多数情况下应该工作,但是一个真正简化的 Nuxt 的版本).
TextClamp
使用配置中的组件( 将来可以添加一个包装来简化) .
import { useComponentsConfig } from '../main'
const config = useComponentsConfig()
<component
:is="config.textClamp"
v-if="config && config.textClamp"
class="fr-mx-1v"
:auto-resize="true"
:text="organization.name"
:max-lines="1"
/>
[注]
坚果甚至不允许装入vue3-text-clamp服务器中的库,所以我们需要在插件配置中使用动态导入,以确保它只被加载到非纳克特环境中.
链接
要在应用程序中进行链接, 您可以使用 <AppLink> 组件。 不知道为什么需要它。 也许我们总是需要 <RouterLink> 从 vue-router 因为每个用户都在使用 vue-router* I think it's used 在链接中添加lang前缀但还没有完成 需要测试.
也许这个组件不应该被曝光,因为我不知道为什么一个用户应该使用这个而不是他们自己的组件(英语:<RouterLink> 或者说 <CdataLink>. ) (中文(简体) )
释放
此软件包作为 @datagouv/components-next 打开 无。 。 。 .
它跟随 语义版本规范。 。 。 .
为了重新发行,你必须:
- 更新版本
- 发布到 npm
- 提交并按下版本更改
更新版本
使用专用 pnpm 命令, 并带有正确的参数 :
pnpm version VERSION
VERSION是:
major当您进行不兼容的 API 更改时minor当您以向后兼容的方式添加函数时patch当您使反向兼容错误修正时版本 发布前和构建元数据的其他标签可作为MAJOR.MINOR.PATCH格式的扩展.
向国家预防机制公布
pnpm login
pnpm run publish-stable
许可证
此组件库根据 MIT 许可证,这与主要项目相同。 这允许在其他项目中随意使用部件.
详情见 自由主义 文件在主工程目录中.