@plasmicpkgs/plasmic-rich-components 1.0.79 → 1.0.80

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.
@@ -1,8 +1,9 @@
1
1
  import registerComponent from '@plasmicapp/host/registerComponent';
2
2
  import '@plasmicapp/host/registerGlobalContext';
3
- import { ProDescriptions, ProLayout, ProTable, TableDropdown } from '@ant-design/pro-components';
3
+ import { ProDescriptions, ProLayout, ProConfigProvider, ProTable, TableDropdown } from '@ant-design/pro-components';
4
4
  import React, { useState, useEffect, useRef } from 'react';
5
- import { Checkbox, Switch, Empty, Dropdown, Button } from 'antd';
5
+ import { Checkbox, Switch, Empty, theme, ConfigProvider, Dropdown, Button } from 'antd';
6
+ import { tinycolor } from '@ctrl/tinycolor';
6
7
  import { LogoutOutlined, PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
7
8
  import { createObjectCsvStringifier } from 'csv-writer-browser';
8
9
  import fastStringify from 'fast-stringify';
@@ -944,10 +945,20 @@ function useIsClient() {
944
945
  function capitalize(text) {
945
946
  return text.slice(0, 1).toUpperCase() + text.slice(1);
946
947
  }
948
+ function isLight(color) {
949
+ var _a = tinycolor(color).toRgb(), r = _a.r, g = _a.g, b = _a.b;
950
+ return r * 0.299 + g * 0.587 + b * 0.114 > 186;
951
+ }
947
952
 
953
+ function omitUndefined(x) {
954
+ return Object.fromEntries(Object.entries(x).filter(function (_a) {
955
+ _a[0]; var v = _a[1];
956
+ return v !== undefined;
957
+ }));
958
+ }
948
959
  function RichLayout(_a) {
949
960
  var _b, _c, _d;
950
- var children = _a.children, navMenuItems = _a.navMenuItems, _e = _a.rootUrl, rootUrl = _e === void 0 ? "/" : _e, actionsChildren = _a.actionsChildren, footerChildren = _a.footerChildren, avatarLabel = _a.avatarLabel, avatarImage = _a.avatarImage, showAvatarMenu = _a.showAvatarMenu, className = _a.className, layoutProps = __rest(_a, ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className"]);
961
+ var children = _a.children, navMenuItems = _a.navMenuItems, _e = _a.rootUrl, rootUrl = _e === void 0 ? "/" : _e, actionsChildren = _a.actionsChildren, footerChildren = _a.footerChildren, avatarLabel = _a.avatarLabel, avatarImage = _a.avatarImage, showAvatarMenu = _a.showAvatarMenu, className = _a.className, simpleNavTheme = _a.simpleNavTheme, layoutProps = __rest(_a, ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className", "simpleNavTheme"]);
951
962
  var isClient = useIsClient();
952
963
  var _f = useState(undefined), pathname = _f[0], setPathname = _f[1];
953
964
  useEffect(function () {
@@ -955,12 +966,88 @@ function RichLayout(_a) {
955
966
  setPathname(location.pathname);
956
967
  }
957
968
  }, []);
969
+ var token = theme.useToken().token;
970
+ var origTextColor = token.colorTextBase;
971
+ function getNavBgColor() {
972
+ var _a, _b;
973
+ var scheme = (_a = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) !== null && _a !== void 0 ? _a : "default";
974
+ switch (scheme) {
975
+ case "primary":
976
+ return token.colorPrimary;
977
+ case "dark":
978
+ // Ant default dark blue Menu color.
979
+ return "#011528";
980
+ case "custom":
981
+ return (_b = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.customBgColor) !== null && _b !== void 0 ? _b : token.colorBgBase;
982
+ case "light":
983
+ // Just use this sorta ugly gray if using 'light' scheme in 'dark' mode.
984
+ // Otherwise using light scheme in light mode.
985
+ return "#fff";
986
+ case "default":
987
+ return token.colorBgBase || "#fff";
988
+ }
989
+ }
990
+ var navBgColor = getNavBgColor();
991
+ // Dynamically determine whether we need to change the text to black/white or not, based on background color.
992
+ // We don't want light-on-light or dark-on-dark, so if both isNavBgLight and isOrigTextLight are the same, then need to change.
993
+ // If no need to change, we leave text color as is.
994
+ var isNavBgLight = isLight(navBgColor);
995
+ var isOrigTextLight = isLight(origTextColor);
996
+ // Ant will interpret "" as defaulting to "#fff" for dark mode and "#000" in light mode.
997
+ var navTextColor = isNavBgLight !== isOrigTextLight ? undefined : "";
958
998
  if (!isClient) {
959
999
  return null;
960
1000
  }
961
1001
  return (React.createElement("div", { className: className },
962
1002
  React.createElement("style", null, ".ant-pro-layout-bg-list {\n display: none;\n }"),
963
1003
  React.createElement(ProLayout, __assign({}, layoutProps, {
1004
+ // Theme just the header. If you simply pass in navTheme=realDark, it affects all main content as well.
1005
+ //
1006
+ // What we're doing is telling Ant to use the dark mode algorithm. However, dark mode algorithm doesn't change
1007
+ // the seed tokens for colorTextBase and colorBgBase - it only fills in #fff and #000 for these if they are
1008
+ // unset (""). So that's why further up we may be setting the text color to "".
1009
+ //
1010
+ // I think it doesn't matter too much what is the colorBgBase, since we are setting (Pro-specific) `tokens`
1011
+ // further down for actually setting the fill of the nav sections. What matters is the text color - if we're
1012
+ // showing a dark background, then we want the text to be white.
1013
+ //
1014
+ // We could specify darkAlgorithm to ConfigProvider, but IIRC Pro might be setting some of its own tokens
1015
+ // based on whether dark is being specified to the ProConfigProvider. So that's why we need that.
1016
+ //
1017
+ // ProConfigProvider does first read/inherit the theme/tokens from the surrounding ConfigProvider.
1018
+ headerRender: function (_props, defaultDom) { return (React.createElement(ConfigProvider, { theme: { token: omitUndefined({ colorTextBase: navTextColor }) } },
1019
+ React.createElement(ProConfigProvider, { dark: !isNavBgLight }, defaultDom))); }, token: {
1020
+ header: omitUndefined({
1021
+ colorBgHeader: navBgColor,
1022
+ }),
1023
+ // Ideally, we'd do something similar to headerRender above, and just specify general dark mode to specify
1024
+ // whether all components/text should be light.
1025
+ // But for some reason it doesn't work, causing the bg color to be ignored (just the default dark Menu color),
1026
+ // *and* the text is just dark as well.
1027
+ // Haven't yet been able to unravel the pro components code to figure out the proper way to do this, so just
1028
+ // bluntly specifying tokens here, as recommended in some GitHub issue.
1029
+ sider: isNavBgLight
1030
+ ? undefined
1031
+ : {
1032
+ colorBgCollapsedButton: navBgColor,
1033
+ colorTextCollapsedButtonHover: "rgba(255,255,255,0.85)",
1034
+ colorTextCollapsedButton: "rgba(255,255,255,0.65)",
1035
+ colorMenuBackground: navBgColor,
1036
+ colorBgMenuItemCollapsedHover: "rgba(0,0,0,0.06)",
1037
+ colorBgMenuItemCollapsedSelected: "rgba(0,0,0,0.15)",
1038
+ colorBgMenuItemCollapsedElevated: "rgba(0,0,0,0.85)",
1039
+ colorMenuItemDivider: "rgba(255,255,255,0.15)",
1040
+ colorBgMenuItemHover: "rgba(0,0,0,0.06)",
1041
+ colorBgMenuItemSelected: "rgba(0,0,0,0.15)",
1042
+ colorTextMenuSelected: "#fff",
1043
+ colorTextMenuItemHover: "rgba(255,255,255,0.75)",
1044
+ colorTextMenu: "rgba(255,255,255,0.75)",
1045
+ colorTextMenuSecondary: "rgba(255,255,255,0.65)",
1046
+ colorTextMenuTitle: "rgba(255,255,255,0.95)",
1047
+ colorTextMenuActive: "rgba(255,255,255,0.95)",
1048
+ colorTextSubMenuSelected: "#fff",
1049
+ },
1050
+ },
964
1051
  // Tweak defaults. ProLayout is janky and has terrible docs!
965
1052
  layout: (_b = layoutProps.layout) !== null && _b !== void 0 ? _b : "top", fixedHeader: (_c = layoutProps.fixedHeader) !== null && _c !== void 0 ? _c : false, fixSiderbar:
966
1053
  // Doesn't stretch full height if you set this to false and you're in mix mode.
@@ -977,7 +1064,7 @@ function RichLayout(_a) {
977
1064
  // collapsedShowGroupTitle: true,
978
1065
  defaultOpenAll: true,
979
1066
  // hideMenuWhenCollapsed: true,
980
- }, avatarProps: showAvatarMenu && false
1067
+ }, avatarProps: showAvatarMenu
981
1068
  ? {
982
1069
  src: avatarImage,
983
1070
  size: "small",
@@ -1027,7 +1114,7 @@ function generateNavMenuType(remainingDepth, displayName, defaultValue) {
1027
1114
  }
1028
1115
  var richLayoutMeta = {
1029
1116
  name: "hostless-rich-layout",
1030
- displayName: "Rich Page Layout",
1117
+ displayName: "Rich App Layout",
1031
1118
  props: {
1032
1119
  children: {
1033
1120
  type: "slot",
@@ -1066,6 +1153,26 @@ var richLayoutMeta = {
1066
1153
  }); }),
1067
1154
  defaultValueHint: "top",
1068
1155
  },
1156
+ simpleNavTheme: {
1157
+ displayName: "Theme",
1158
+ type: "object",
1159
+ fields: {
1160
+ scheme: {
1161
+ type: "choice",
1162
+ options: ["default", "primary", "light", "dark", "custom"].map(function (v) { return ({
1163
+ label: capitalize(v),
1164
+ value: v,
1165
+ }); }),
1166
+ defaultValueHint: "default",
1167
+ },
1168
+ customBgColor: {
1169
+ type: "color",
1170
+ displayName: "Custom color",
1171
+ hidden: function (props) { var _a; return !(((_a = props.simpleNavTheme) === null || _a === void 0 ? void 0 : _a.scheme) === "custom"); },
1172
+ defaultValue: "#D73B58",
1173
+ },
1174
+ },
1175
+ },
1069
1176
  // Advanced, show later
1070
1177
  /*
1071
1178
  siderMenuType: {
@@ -1083,18 +1190,6 @@ var richLayoutMeta = {
1083
1190
  options: ["Fluid", "Fixed"],
1084
1191
  defaultValueHint: "Fluid",
1085
1192
  },
1086
- navTheme: {
1087
- displayName: "Theme",
1088
- type: "choice",
1089
- options: [
1090
- { value: "realDark", label: "Dark" },
1091
- { value: "light", label: "Light" },
1092
- ],
1093
- },
1094
- colorPrimary: {
1095
- displayName: "Primary color",
1096
- type: "color",
1097
- },
1098
1193
  */
1099
1194
  fixedHeader: {
1100
1195
  displayName: "Sticky header",
@@ -1144,6 +1239,7 @@ var richLayoutMeta = {
1144
1239
  defaultStyles: {
1145
1240
  width: "full-bleed",
1146
1241
  height: "stretch",
1242
+ minHeight: "100vh",
1147
1243
  },
1148
1244
  importName: "RichLayout",
1149
1245
  importPath: "@plasmicpkgs/plasmic-rich-components",