From 640af67d323f19dbcdc0227fcc5a63da66b339dd Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 26 Jan 2024 21:23:22 +0400 Subject: [PATCH] Up trait images --- docs/.vuepress/public/trait-categories.png | Bin 0 -> 6420 bytes docs/.vuepress/styles/index.styl | 7 ++++ docs/modules/Traits.md | 42 ++++++++++++++++++--- 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 docs/.vuepress/public/trait-categories.png diff --git a/docs/.vuepress/public/trait-categories.png b/docs/.vuepress/public/trait-categories.png new file mode 100644 index 0000000000000000000000000000000000000000..f6fcf5dda7683f99caafc0a51acd0703834936eb GIT binary patch literal 6420 zcma)B2Q*w=yGD@cL>s+J^fr2w=xvl}QKOsDd#};SXruQsM4|=JlD@7w2_Zcp78VwXriRKBEG%rq z?R9qV&TWrSND}4ktwCSMNL58eMM6SCPEJlxP;hB!NmNwS$jAr+ftZ<@nVOm|E-pGa zI4mqI3=R%XOiawq&Z1DL&d$z{A3xgJ*$od5BaujTb@haV1T8HsMMXtROG^X-;pgYq z+uQr>*|Yxseh>&$Qc~jN(wNEE8v?GMh`Lh_H7o8>9D2q!q%l1{w;3-bljZ2vF7z9~3Vh>ABd z?WPOfH1OaxV?9F#u`=7hyFk(E1k#8~v@JLyS{AAnr)R{2)~_+)iE6VeS`}(tqj@() zNqhMi2U;B#R-rXTPrN7WPsQTh8ku@F%B#GX4sr;uOf%Fx%+hYDk2utHaNKBguNs-? ziqF}W_&C*!C%CuKF}Ojz~l>*rpFpD3RkTy{!_Bv%~2lr25ImZ=!p!ui?W zPt5$oX4#FAh^wfKFuVNcyjpL5g-V7n7)O6yY#%SHD)ER%9xG^#h%OYnvlqZJWsgjW zh3<20VU&chC5YoPB5Lofx^CYy1C{rPp!AM?3(6}91BKY=;+Zrqrf}}JQdvY}&BL^g zOt^X-bIRiwSxqZ~rpe@n=%Ez`9Q3gAH;q#@K%`{{e`?yu%g+bi_SPZzUJO3)DS#hV z-2$&QGs7tsv9h3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cs*!4k(KKof{{FTI^hY@hIQu z9hPsuV(v8a-wkZxm0q^hDZ4KH``) or you can also bind them to the properties of your components and react to their changes. ::: warning -This guide is referring to GrapesJS v0.15.3 or higher.

+This guide is referring to GrapesJS v0.21.9 or higher.

To get a better understanding of the content in this guide we recommend reading [Components](Components.html) first ::: @@ -22,7 +22,7 @@ Generally, you define traits on the definition of your new custom components (or All components, by default, contain two traits: `id` and `title` (at the moment of writing). So, if you select an input and open the Settings panel you will see this: - +Default traits We can start by creating a new custom `input` component in this way: @@ -59,7 +59,7 @@ editor.Components.addType('input', { Now the result will be - +Input with custom traits If you want you can also define traits dynamically via functions, which will be created on component initialization. It might be useful if you need to create traits based on some other component characteristic. @@ -136,6 +136,36 @@ editor.Components.addType('input', { }) ``` +### Categories + +It's possible to group your traits into categories, as shown below. + +Traits with categories + +```js +const category1 = { id: 'first', label: 'First category' }; +const category2 = { id: 'second', label: 'Second category', open: false }; + +editor.Components.addType('input', { + model: { + defaults: { + // ... + traits: [ + { name: 'trait-1', category: category1 }, + { name: 'trait-2', category: category1 }, + { name: 'trait-3', category: category2 }, + { name: 'trait-4', category: category2 }, + // Traits without categories will be rendered at the bottom + { name: 'trait-5' }, + { name: 'trait-6' }, + ], + }, + } +}) +``` + + + ## Built-in trait types GrapesJS comes along with few built-in types that you can use to define your traits: @@ -270,7 +300,7 @@ In that case, you can define a totally new type of trait and bind any kind of el Let's update the default `link` Component with a new kind of trait. This is the default situation of traits for a simple link. - +Default link component Let's just replace all of its traits with a new one, `href-next`, which will allow the user to select the type of href (eg. 'url', 'email', etc.) @@ -343,7 +373,7 @@ editor.Traits.addType('href-next', { From the example above we simply created our custom inputs (by giving also the possibility to use `option` trait property) and defined some input switch behavior on the type change. Now the result would be something like this - +Link with traits ### Update layout @@ -393,7 +423,7 @@ editor.Traits.addType('href-next', { }); ``` - +Basic custom link trait In this case, the result will be quite raw and unstyled but the point of custom trait types is to allow you to reuse your own styled inputs, probably already designed and defined (or implemented in some UI framework). For now, let's keep the default input wrapper and continue with the integration of our custom trait.