ant-design/293411c6-async.3cd9e434.js
2024-11-20 18:30:54 +00:00

1 line
4.4 KiB
JavaScript

(("undefined"!=typeof globalThis?globalThis:self).makoChunk_antd=("undefined"!=typeof globalThis?globalThis:self).makoChunk_antd||[]).push([["293411c6"],{"293411c6":function(e,a,t){"use strict";t.d(a,"__esModule",{value:!0}),t.d(a,"texts",{enumerable:!0,get:function(){return o;}}),t("9763cd08");let o=[{value:"In the v5 release announce, our design team mentioned that we will provide a happy work theme. This part of the work is still in progress, but we have made some progress and would like to share it with you here.",paraId:0},{value:"You can directly use ",paraId:1,tocIndex:0},{value:"@ant-design/happy-work-theme",paraId:1,tocIndex:0},{value:" to switch theme effects (or continue reading to see what we have done):",paraId:1,tocIndex:0},{value:"import { HappyProvider } from '@ant-design/happy-work-theme';\n\nexport default () => (\n <HappyProvider>\n <Button />\n </HappyProvider>\n);\n",paraId:2,tocIndex:0},{value:"There is a special design interaction in Ant Design, which is the click wave effect on some components. You can see them everywhere:",paraId:3,tocIndex:1},{value:'In the past major versions, this wave effect could not be modified. If developers want to turn it off, they even need to do some "magic code" to achieve it. So when the designer proposed a happy work theme, as a developer, we think this is a good time to make some changes.',paraId:4,tocIndex:1},{value:"Wave effect is actually an component, which listens to the click event of the child component. Then add a ",paraId:5,tocIndex:2},{value:"box-shadow",paraId:5,tocIndex:2},{value:" animation to generate a wave effect:",paraId:5,tocIndex:2},{value:"// Sample code.\nconst Button = (\n <Wave>\n <button />\n </Wave>\n);\n",paraId:6,tocIndex:2},{value:"In the early design (",paraId:7,tocIndex:2},{value:"#40111",paraId:7,tocIndex:2},{value:"), we hope that the wave customization ability belongs to part of the Design Token. But in this way, the Design Token will become a bit too complicated, from the original pure ",paraId:7,tocIndex:2},{value:"string | number",paraId:7,tocIndex:2},{value:" type to ",paraId:7,tocIndex:2},{value:"string | number | Function<T>",paraId:7,tocIndex:2},{value:". From the API design point of view, ",paraId:7,tocIndex:2},{value:"Function<T>",paraId:7,tocIndex:2},{value:" also has a bad smell, and if there are new customization requirements in the future, the type of Function will become more and more divergent. So ",paraId:7,tocIndex:2},{value:"#40111",paraId:7,tocIndex:2},{value:" stays in the Draft version forever.",paraId:7,tocIndex:2},{value:"Next, we choose to put it in ConfigProvider. ConfigProvider is a global configuration component, which can affect all child components. Its API has also included a lot of component configuration capabilities, so we only need to add a ",paraId:8,tocIndex:3},{value:"wave",paraId:8,tocIndex:3},{value:" property:",paraId:8,tocIndex:3},{value:"<ConfigProvider wave={{ showEffect }}>\n <Button />\n</ConfigProvider>\n",paraId:9,tocIndex:3},{value:"Click to ",paraId:10,tocIndex:3},{value:"view ConfigProvider demo",paraId:11,tocIndex:3},{value:".",paraId:10,tocIndex:3},{value:"showEffect",paraId:12,tocIndex:3},{value:" method will tell you the DOM node that needs to generate the effect. This node has been encapsulated and will always correspond to the correct element (for example, Button is itself, and Radio will find the circle shape DOM from ",paraId:12,tocIndex:3},{value:"label",paraId:12,tocIndex:3},{value:"). And tell you which component it is and which Design Token the current node belongs to:",paraId:12,tocIndex:3},{value:"type ShowEffect = (target: HTMLElement, info: { component: string; token: GlobalToken }) => void;\n",paraId:13,tocIndex:3},{value:"Through Design Token, you can implement effects that conform to the current theme. For example, in the GIF at the beginning of the article, when the theme color changes, we can get the current theme color and add the corresponding effect.",paraId:14,tocIndex:3},{value:"Happy work theme is still in progress, and we will gradually add more capabilities in subsequent versions. The HappyProvider provided by ",paraId:15,tocIndex:4},{value:"@ant-design/happy-work-theme",paraId:15,tocIndex:4},{value:' currently replaces the wave effect through ConfigProvider. We plan that developers will not need to make additional changes in the future, and will gradually add more "happiness" through HappyProvider as the version iterates. Stay tuned.',paraId:15,tocIndex:4}];}}]);