@bigbinary/neeto-themes-frontend 2.0.9 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # neeto-themes-nano
2
2
 
3
- The `neeto-themes-nano` acts as the source of truth for the new nano's structure,
4
- configs, data etc.
3
+ The `neeto-themes-nano` allows us to build and use themes within neeto applications. This nano exports `@bigbinary/neeto-themes-frontend` NPM package and `neeto-themes-engine` Rails engine.
5
4
 
6
5
  ## Contents
7
6
 
@@ -51,25 +50,71 @@ configs, data etc.
51
50
  bundle exec rails db:migrate
52
51
  ```
53
52
 
54
- #### Usage
53
+ 5. Add the following line to `models/organization.rb` file.
55
54
 
56
- 1. Replace NeetoThemesNano with your project name
55
+ ```ruby
56
+ has_many :themes, class_name: "NeetoThemesEngine::Theme", as: :owner
57
+ ```
58
+ 6. Configure model to add below association to attach theme.
57
59
 
58
- Create a `script.rb` file in the project root and paste the script from the
59
- following file.
60
+ ```ruby
61
+ has_one :theme_entity, as: :themeable, class_name: "NeetoThemesEngine::ThemeEntity", dependent: :destroy
62
+ has_one :theme, through: :theme_entity, class_name: "NeetoThemesEngine::Theme"
63
+ ```
60
64
 
61
- [Replace project name script](./docs/engine/replace-project-name-script.md)
65
+ ### Usage
62
66
 
63
- 2. Run the file using the following command:
67
+ 1. **Create an engine initializer**
64
68
 
65
- ```shell
66
- ruby script.rb
69
+ Create a file named `neeto_themes_engine.rb` in the `config/initializers` folder.
70
+
71
+ 2. **Customize theme schema**
72
+
73
+ The engine supports customizing theme schemas based on the needs of the host application. This schema will be used in the frontend to render the theme properties. Eg:
74
+
75
+ ```ruby
76
+ NeetoThemesEngine.theme_properties_schema = [
77
+ { kind: "color", key: "primary_color", default_value: "#2D36D4" },
78
+ { kind: "color", key: "secondary_color", default_value: "#ECF4FF" },
79
+ ]
67
80
  ```
68
81
 
69
- Notes ⚠️
82
+ Each object in the array should have the following keys:
83
+ - `key`: The unique identifier for the theme property.
84
+
85
+ - `kind`: The kind of the theme property.
86
+
87
+ Optional keys that can be included:
88
+
89
+ - `default_value`: Sets a default value when creating a new theme.
90
+
91
+ - `hidden`: This boolean prop helps to hide the property from the UI but allows to use it as CSS variable.
92
+
93
+ - `depends_on`: Provides a dependency on other properties. If a key is provided, it will check for its value and only appear in the UI if the dependent property is present.
94
+
95
+ 3. **Provide a css variable prefix**
96
+
97
+ This value will be used to prefix all CSS variables. Eg:
98
+
99
+ ```ruby
100
+ NeetoThemesEngine.css_variable_prefix = "neeto-cal"
101
+ ```
102
+ variable generated for the theme property `primary_color` will be `--neeto-cal-primary-color`.
103
+
104
+ 4. **Provide the entities to which the theme property is attached**
70
105
 
71
- - Don't commit this file.
72
- - Project name should be given in PascalCase.
106
+ This value will be used to determine the entity to which the theme property is attached. We can provide multiple entities. Eg:
107
+
108
+ ```ruby
109
+ NeetoThemesEngine.valid_themeable_types = ["Meeting", "Booking"]
110
+ ```
111
+ 5. **Provide a default theme name** (Optional)
112
+
113
+ This provided value will be used to identify the default theme. If not provided, the default theme will be named "Plain blue".
114
+
115
+ ```ruby
116
+ NeetoThemesEngine.default_theme_name = "My theme"
117
+ ```
73
118
 
74
119
  ### Frontend package
75
120
 
@@ -84,20 +129,45 @@ Notes ⚠️
84
129
  ### Instructions for development
85
130
  Check the [Frontend package development guide](https://neeto-engineering.neetokb.com/p/a-d34cb4b0) for step-by-step instructions to develop the frontend package.
86
131
 
87
- #### Usage
132
+ ### Usage
133
+
134
+ #### Components
88
135
 
89
- 1. Import `WelcomeScreen` component from "@bigbinary/neeto-themes-frontend"
136
+ 1. Import the `NeetoThemesBuilder` component from `@bigbinary/neeto-themes-frontend`:
90
137
 
91
138
  ```javascript
92
139
  import React from "react";
140
+ import { NeetoThemesBuilder } from "@bigbinary/neeto-themes-frontend";
141
+
142
+ const App = () => (
143
+ <NeetoThemesBuilder
144
+ entityId={meeting?.id}
145
+ entityType="Meeting"
146
+ thumbnail={Thumbnail}
147
+ >
148
+ <Preview />
149
+ </NeetoThemesBuilder>
150
+ );
93
151
 
94
- import { WelcomeScreen } from "@bigbinary/neeto-themes-frontend";
152
+ export default App;
95
153
 
96
- const App = () => <WelcomeScreen />;
154
+ #### hooks
97
155
 
98
- export default App;
156
+ 1. Import `useThemeUtils` hook from "@bigbinary/neeto-themes-frontend"
157
+
158
+ ```javascript
159
+ import { useThemeUtils } from "@bigbinary/neeto-themes-frontend";
160
+
161
+ const { setTheme,previewingTheme, currentTheme } = useThemeUtils();
99
162
  ```
100
163
 
164
+ - `setTheme`: This method is used to set the theme for the entity.
165
+
166
+ - `previewingTheme`: This object contains the currently previewing theme.
167
+
168
+ - `currentTheme`: This object contains the current theme which is applied to the entity.
169
+
170
+
101
171
  ## Instructions for Publishing
102
172
 
103
173
  Consult the
package/dist/index.cjs.js CHANGED
@@ -601,6 +601,7 @@ var Card$2 = function Card(_ref) {
601
601
  children = _ref.children;
602
602
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
603
603
  className: "neeto-ui-border-gray-300 neeto-ui-rounded-lg neeto-ui-bg-white space-y-3 border p-4",
604
+ "data-cy": "theme-".concat(neetoCist.hyphenate(title), "-properties"),
604
605
  children: [title && /*#__PURE__*/jsxRuntime.jsx("div", {
605
606
  className: "flex items-center justify-between",
606
607
  children: /*#__PURE__*/jsxRuntime.jsx(Typography__default["default"], {
@@ -982,7 +983,9 @@ var Properties = function Properties(_ref) {
982
983
  var index = neetoCist.findIndexBy({
983
984
  key: name
984
985
  }, values.properties);
985
- if (index !== -1) setFieldValue("properties[".concat(index, "].value"), value);
986
+ if (index !== -1 && values.properties[index].value !== value) {
987
+ setFieldValue("properties[".concat(index, "].value"), value);
988
+ }
986
989
  setVariable(neetoCist.snakeToCamelCase(name), variableValue !== null && variableValue !== void 0 ? variableValue : value);
987
990
  };
988
991
  var handleOverlayChange = function handleOverlayChange(key, value) {
@@ -1655,6 +1658,7 @@ var Themes = function Themes(_ref) {
1655
1658
  children: t("neetoThemes.build.leftSideBar.themes.systemThemes")
1656
1659
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
1657
1660
  className: "flex flex-col gap-4 px-4 pb-10 lg:px-5 xl:px-6",
1661
+ "data-cy": "system-themes",
1658
1662
  children: filteredDefaultThemes.map(function (theme) {
1659
1663
  return /*#__PURE__*/react.createElement(Card$1, {
1660
1664
  onApplyTheme: onApplyTheme,
@@ -1680,6 +1684,7 @@ var Themes = function Themes(_ref) {
1680
1684
  children: t("neetoThemes.build.leftSideBar.themes.customThemes")
1681
1685
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
1682
1686
  className: "flex flex-col gap-4 px-6",
1687
+ "data-cy": "custom-themes",
1683
1688
  children: filteredThemes.map(function (theme) {
1684
1689
  var isActive = (currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.id) === theme.id;
1685
1690
  var isPreviewing = (previewingTheme === null || previewingTheme === void 0 ? void 0 : previewingTheme.id) === theme.id;