mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["46417"],{41452:function(e,s,a){a.d(s,{A:()=>n});let n={tabItem:"tabItem_pnkT"}},18416:function(e,s,a){a.d(s,{A:()=>n});let n={tabList:"tabList_Qoir",tabItem:"tabItem_AQgk"}},11344:function(e,s,a){a.d(s,{A:()=>n});let n={apiTable:"apiTable_e8hp"}},19377:function(e,s,a){a.r(s),a.d(s,{assets:()=>d,contentTitle:()=>u,default:()=>f,frontMatter:()=>c,metadata:()=>n,toc:()=>h});var n=a(74569),r=a(74848),t=a(56151),l=a(14729),i=a(13899),o=a(6125);let c={sidebar_position:9,slug:"/api/plugins/@docusaurus/plugin-css-cascade-layers"},u="\u{1F4E6} plugin-css-cascade-layers",d={},h=[{value:"Installation",id:"installation",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Types",id:"types",level:3},{value:"<code>Layers</code>",id:"EditUrlFunction",level:4},{value:"Example configuration",id:"ex-config",level:3}];function p(e){let s={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,t.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.header,{children:(0,r.jsx)(s.h1,{id:"-plugin-css-cascade-layers",children:"\u{1F4E6} plugin-css-cascade-layers"})}),"\n","\n",(0,r.jsx)(s.admonition,{title:"Experimental",type:"caution",children:(0,r.jsxs)(s.p,{children:["This plugin is mostly designed to be used internally by the classic preset through the ",(0,r.jsxs)(s.a,{href:"/docs/api/docusaurus-config#future",children:["Docusaurus ",(0,r.jsx)(s.code,{children:"future.v4.useCssCascadeLayers"})," flag"]}),", although it can also be used as a standalone plugin. Please ",(0,r.jsx)(s.a,{href:"https://github.com/facebook/docusaurus/pull/11142",children:"let us know here"})," if you have a use case for it and help us design an API that makes sense for the future of Docusaurus."]})}),"\n",(0,r.jsxs)(s.p,{children:["A plugin for wrapping CSS modules of your Docusaurus site in ",(0,r.jsx)(s.a,{href:"https://css-tricks.com/css-cascade-layers/",children:"CSS Cascade Layers"}),". This modern CSS feature is widely supported by all browsers. It allows grouping CSS rules in layers of specificity and gives you more control over the CSS cascade."]}),"\n",(0,r.jsx)(s.p,{children:"Use this plugin to:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["apply a top-level ",(0,r.jsx)(s.code,{children:"@layer myLayer { ... }"})," block rule around any CSS module, including un-layered third-party CSS."]}),"\n",(0,r.jsx)(s.li,{children:"define an explicit layer ordering"}),"\n"]}),"\n",(0,r.jsx)(s.admonition,{type:"caution",children:(0,r.jsxs)(s.p,{children:["To use this plugin properly, it's recommended to have a solid understanding of ",(0,r.jsx)(s.a,{href:"https://css-tricks.com/css-cascade-layers/",children:"CSS Cascade Layers"}),", the ",(0,r.jsx)(s.a,{href:"https://developer.mozilla.org/docs/Web/CSS/CSS_cascade/Cascade",children:"CSS Cascade"})," and ",(0,r.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_cascade/Specificity",children:"specificity"}),"."]})}),"\n",(0,r.jsx)(s.h2,{id:"installation",children:"Installation"}),"\n",(0,r.jsxs)(l.A,{groupId:"npm2yarn",children:[(0,r.jsx)(i.A,{value:"npm",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"npm install --save @docusaurus/plugin-css-cascade-layers\n"})})}),(0,r.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"yarn add @docusaurus/plugin-css-cascade-layers\n"})})}),(0,r.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"pnpm add @docusaurus/plugin-css-cascade-layers\n"})})}),(0,r.jsx)(i.A,{value:"bun",label:"Bun",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"bun add @docusaurus/plugin-css-cascade-layers\n"})})})]}),"\n",(0,r.jsx)(s.admonition,{type:"tip",children:(0,r.jsxs)(s.p,{children:["If you use the preset ",(0,r.jsx)(s.code,{children:"@docusaurus/preset-classic"}),", this plugin is automatically configured for you with the ",(0,r.jsx)(s.a,{href:"/docs/api/docusaurus-config#future",children:(0,r.jsx)(s.code,{children:"siteConfig.future.v4.useCssCascadeLayers"})})," flag."]})}),"\n",(0,r.jsx)(s.h2,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsx)(s.p,{children:"Accepted fields:"}),"\n",(0,r.jsx)(o.A,{children:(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Name"}),(0,r.jsx)(s.th,{children:"Type"}),(0,r.jsx)(s.th,{children:"Default"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsx)(s.tbody,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"layers"})}),(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"Layers"})}),(0,r.jsx)(s.td,{children:(0,r.jsx)(s.strong,{children:"Built-in layers"})}),(0,r.jsx)(s.td,{children:"An object representing all the CSS cascade layers you want to use, and whether the layer should be applied to a given file path. See examples and types below."})]})})]})}),"\n",(0,r.jsx)(s.h3,{id:"types",children:"Types"}),"\n",(0,r.jsx)(s.h4,{id:"EditUrlFunction",children:(0,r.jsx)(s.code,{children:"Layers"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-ts",children:"type Layers = Record<\n string, // layer name\n (filePath: string) => boolean // layer matcher\n>;\n"})}),"\n",(0,r.jsxs)(s.p,{children:["The ",(0,r.jsx)(s.code,{children:"layers"})," object is defined by:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"key: the name of a layer"}),"\n",(0,r.jsx)(s.li,{children:"value: a function to define if a given CSS module file should be in that layer"}),"\n"]}),"\n",(0,r.jsxs)(s.admonition,{title:"Order matters",type:"caution",children:[(0,r.jsx)(s.p,{children:"The object order matters:"}),(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"the keys order defines an explicit CSS layer order"}),"\n",(0,r.jsx)(s.li,{children:"when multiple layers match a file path, only the first layer will apply"}),"\n"]})]}),"\n",(0,r.jsx)(s.h3,{id:"ex-config",children:"Example configuration"}),"\n",(0,r.jsx)(s.p,{children:"You can configure this plugin through plugin options."}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-js",children:"const options = {\n layers: {\n 'docusaurus.infima': (filePath) =>\n filePath.includes('/node_modules/infima/dist'),\n 'docusaurus.theme-classic': (filePath) =>\n filePath.includes('/node_modules/@docusaurus/theme-classic/lib'),\n },\n};\n"})})]})}function f(e={}){let{wrapper:s}={...(0,t.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},13899:function(e,s,a){a.d(s,{A:()=>l});var n=a(74848);a(96540);var r=a(11118),t=a(41452);function l({children:e,hidden:s,className:a}){return(0,n.jsx)("div",{role:"tabpanel",className:(0,r.A)(t.A.tabItem,a),hidden:s,children:e})}},14729:function(e,s,a){a.d(s,{A:()=>f});var n=a(74848),r=a(96540),t=a(11118),l=a(85208),i=a(31191),o=a(17060),c=a(30926),u=a(18416);function d({className:e,block:s,selectedValue:a,selectValue:r,tabValues:l}){let o=[],{blockElementScrollPositionUntilNextRender:c}=(0,i.a_)(),d=e=>{let s=e.currentTarget,n=l[o.indexOf(s)].value;n!==a&&(c(s),r(n))},h=e=>{let s=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{let a=o.indexOf(e.currentTarget)+1;s=o[a]??o[0];break}case"ArrowLeft":{let a=o.indexOf(e.currentTarget)-1;s=o[a]??o[o.length-1]}}s?.focus()};return(0,n.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.A)("tabs",{"tabs--block":s},e),children:l.map(({value:e,label:s,attributes:r})=>(0,n.jsx)("li",{role:"tab",tabIndex:a===e?0:-1,"aria-selected":a===e,ref:e=>{o.push(e)},onKeyDown:h,onClick:d,...r,className:(0,t.A)("tabs__item",u.A.tabItem,r?.className,{"tabs__item--active":a===e}),children:s??e},e))})}function h({lazy:e,children:s,selectedValue:a}){let l=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){let e=l.find(e=>e.props.value===a);return e?(0,r.cloneElement)(e,{className:(0,t.A)("margin-top--md",e.props.className)}):null}return(0,n.jsx)("div",{className:"margin-top--md",children:l.map((e,s)=>(0,r.cloneElement)(e,{key:s,hidden:e.props.value!==a}))})}function p(e){let s=(0,o.u)(e);return(0,n.jsxs)("div",{className:(0,t.A)(l.G.tabs.container,"tabs-container",u.A.tabList),children:[(0,n.jsx)(d,{...s,...e}),(0,n.jsx)(h,{...s,...e})]})}function f(e){let s=(0,c.A)();return(0,n.jsx)(p,{...e,children:(0,o.v)(e.children)},String(s))}},17060:function(e,s,a){a.d(s,{u:()=>d,v:()=>c});var n=a(96540),r=a(49519),t=a(57190),l=a(11864),i=a(84329),o=a(34123);function c(e){return n.Children.toArray(e).filter(e=>"\n"!==e).map(e=>{if(!e||(0,n.isValidElement)(e)&&function(e){let{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})?.filter(Boolean)??[]}function u({value:e,tabValues:s}){return s.some(s=>s.value===e)}function d(e){let s,{defaultValue:a,queryString:d=!1,groupId:h}=e,p=function(e){let{values:s,children:a}=e;return(0,n.useMemo)(()=>{let e=s??c(a).map(({props:{value:e,label:s,attributes:a,default:n}})=>({value:e,label:s,attributes:a,default:n})),n=(0,i.XI)(e,(e,s)=>e.value===s.value);if(n.length>0)throw Error(`Docusaurus error: Duplicate values "${n.map(e=>e.value).join(", ")}" found in <Tabs>. Every value needs to be unique.`);return e},[s,a])}(e),[f,m]=(0,n.useState)(()=>(function({defaultValue:e,tabValues:s}){if(0===s.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!u({value:e,tabValues:s}))throw Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}let a=s.find(e=>e.default)??s[0];if(!a)throw Error("Unexpected error: 0 tabValues");return a.value})({defaultValue:a,tabValues:p})),[g,y]=function({queryString:e=!1,groupId:s}){let a=(0,r.W6)(),t=function({queryString:e=!1,groupId:s}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,l.aZ)(t),(0,n.useCallback)(e=>{if(!t)return;let s=new URLSearchParams(a.location.search);s.set(t,e),a.replace({...a.location,search:s.toString()})},[t,a])]}({queryString:d,groupId:h}),[x,b]=function({groupId:e}){let s=e?`docusaurus.tab.${e}`:null,[a,r]=(0,o.Dv)(s);return[a,(0,n.useCallback)(e=>{s&&r.set(e)},[s,r])]}({groupId:h}),j=u({value:s=g??x,tabValues:p})?s:null;return(0,t.A)(()=>{j&&m(j)},[j]),{selectedValue:f,selectValue:(0,n.useCallback)(e=>{if(!u({value:e,tabValues:p}))throw Error(`Can't select invalid tab value=${e}`);m(e),y(e),b(e)},[y,b,p]),tabValues:p}}},6125:function(e,s,a){a.d(s,{A:()=>c});var n=a(74848),r=a(96540),t=a(79024),l=a(49519),i=a(11344);let o=r.forwardRef(function({name:e,children:s},a){let i=function(e){let s=e;for(;(0,r.isValidElement)(s);)[s]=r.Children.toArray(s.props.children);if("string"!=typeof s)throw Error(`Could not extract APITable row name from JSX tree:
|
|
${JSON.stringify(e,null,2)}`);return s}(s),o=e?`${e}-${i}`:i,c=`#${o}`,u=(0,l.W6)();return(0,t.A)().collectAnchor(o),(0,n.jsx)("tr",{id:o,tabIndex:0,ref:u.location.hash===c?a:void 0,onClick:e=>{let s="TD"===e.target.tagName.toUpperCase(),a=!!window.getSelection()?.toString();s&&!a&&u.push(c)},onKeyDown:e=>{"Enter"===e.key&&u.push(c)},children:s.props.children})});function c({children:e,name:s}){if("table"!==e.type)throw Error("Bad usage of APITable component.\nIt is probably that your Markdown table is malformed.\nMake sure to double-check you have the appropriate number of columns for each table row.");let[a,t]=r.Children.toArray(e.props.children),l=(0,r.useRef)(null);(0,r.useEffect)(()=>{l.current?.focus()},[l]);let c=r.Children.map(t.props.children,e=>(0,n.jsx)(o,{name:s,ref:l,children:e}));return(0,n.jsxs)("table",{className:i.A.apiTable,children:[a,(0,n.jsx)("tbody",{children:c})]})}},56151:function(e,s,a){a.d(s,{R:()=>l,x:()=>i});var n=a(96540);let r={},t=n.createContext(r);function l(e){let s=n.useContext(t);return n.useMemo(function(){return"function"==typeof e?e(s):{...s,...e}},[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),n.createElement(t.Provider,{value:s},e.children)}},74569:function(e){e.exports=JSON.parse('{"id":"api/plugins/plugin-css-cascade-layers","title":"\u{1F4E6} plugin-css-cascade-layers","description":"This plugin is mostly designed to be used internally by the classic preset through the Docusaurus future.v4.useCssCascadeLayers flag, although it can also be used as a standalone plugin. Please let us know here if you have a use case for it and help us design an API that makes sense for the future of Docusaurus.","source":"@site/docs/api/plugins/plugin-css-cascade-layers.mdx","sourceDirName":"api/plugins","slug":"/api/plugins/@docusaurus/plugin-css-cascade-layers","permalink":"/docs/api/plugins/@docusaurus/plugin-css-cascade-layers","draft":false,"unlisted":false,"editUrl":"https://github.com/facebook/docusaurus/edit/main/website/docs/api/plugins/plugin-css-cascade-layers.mdx","tags":[],"version":"current","lastUpdatedBy":"S\xe9bastien Lorber","lastUpdatedAt":1764958541000,"sidebarPosition":9,"frontMatter":{"sidebar_position":9,"slug":"/api/plugins/@docusaurus/plugin-css-cascade-layers"},"sidebar":"api","previous":{"title":"\u{1F4E6} plugin-ideal-image","permalink":"/docs/api/plugins/@docusaurus/plugin-ideal-image"},"next":{"title":"\u{1F4E6} plugin-pwa","permalink":"/docs/api/plugins/@docusaurus/plugin-pwa"}}')}}]); |