@planningcenter/organization-avatars 1.7.0 → 1.8.1

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),T=require("react-dom"),$=require("@planningcenter/url"),b=require("@planningcenter/tapestry"),I=require("@planningcenter/sweetest-alert"),_=require("@planningcenter/icons/paths/general"),L=require("@planningcenter/icons/paths/services"),E=require("react-dropzone");function B(a){var r,t,o="";if(typeof a=="string"||typeof a=="number")o+=a;else if(typeof a=="object")if(Array.isArray(a)){var d=a.length;for(r=0;r<d;r++)a[r]&&(t=B(a[r]))&&(o&&(o+=" "),o+=t)}else for(t in a)a[t]&&(o&&(o+=" "),o+=t);return o}function W(){for(var a,r,t=0,o="",d=arguments.length;t<d;t++)(a=arguments[t])&&(r=B(a))&&(o&&(o+=" "),o+=r);return o}function G(){const a=document.querySelector('meta[name="csrf-token"]');if(!a||!a.content)throw new Error('CSRF token not found. Ensure your Rails application includes <meta name="csrf-token" content="..."> in the document head.');return a.content}function J(a){const r=a.split("");return[r.shift()?.toUpperCase(),r.join("")].join("")}const X=a=>a==="dark_mode_avatar"?"dark":"light",z=({open:a})=>e.jsxs("h2",{className:"pco-org-avatar__instructions",children:["Drag & drop your logo file to upload, or"," ",e.jsx(b.Button,{label:"browse",kind:"inline-text",onClick:r=>{r.stopPropagation(),a()}})]});function F({avatarUrl:a,organization:r,mode:t,pcoEnv:o,readOnly:d,onAvatarUpdate:x,fallbackAvatarUrl:A}){const[n,f]=c.useState(null),[l,y]=c.useState(!1),[i,p]=c.useState(!1),[u,w]=c.useState(""),q=c.useId(),v=c.useRef(null),g=X(t),m=a||A,D=h=>{const[s]=h;s&&f(Object.assign(s,{preview:URL.createObjectURL(s)}))};c.useEffect(()=>()=>{n?.preview&&(URL.revokeObjectURL(n.preview),w(""))},[n]);const S=async h=>{const s=await fetch($.pcoApiUrl("accounts",{env:o}),{method:"PATCH",headers:{"Content-Type":"application/json","X-CSRF-Token":G(),Accept:"application/json"},body:JSON.stringify({data:{attributes:h}})}),j=await s.json();if(!s.ok)throw j;return j},M=async h=>{if(h.preventDefault(),!(!n||l||i)){y(!0);try{const s=new FileReader,j=await new Promise((k,C)=>{s.onloadend=()=>k(s.result),s.onerror=C,s.readAsDataURL(n)}),N=await S({[t]:j,[`${t}_cache`]:""});f(null),x(t,N.data.attributes[t].url),v.current?.close()}catch{w("We were unable to save your avatar.")}finally{y(!1)}}},U=async()=>{l||i||(p(!0),I.SweetestAlert({type:"danger",title:"Remove this logo?",content:`Removing this logo will mean your light mode logo appear in ${g} mode. This cannot be undone.`,confirmButton:"Remove logo",onConfirm:async()=>{try{await S({[`remove_${t}`]:"1"}),x(t,""),v.current?.close()}catch{w("We were unable to delete your avatar.")}finally{p(!1)}},onCancel:()=>{p(!1)}}))},O=()=>{f(null),w("")};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pco-org-avatar",children:[e.jsx("button",{type:"button",onClick:()=>v.current?.showModal(),disabled:d,className:`pco-org-avatar__button pco-org-avatar__button--${g}`,children:m?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:m,alt:`Church logo for ${r}`}),e.jsx("div",{className:"tds-btn tds-btn--interaction tds-btn--icononly",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:_.pencil})})})]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"48",height:"48",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:L.image})}),e.jsx("div",{className:"tds-btn tds-btn--interaction tds-btn--icononly",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:_.pencil})})})]})}),e.jsxs("div",{className:"pco-org-avatar__label",children:[J(g)," mode"]})]}),T.createPortal(e.jsx("dialog",{id:q,ref:v,className:"pco-org-avatar__dialog",onClose:O,children:e.jsxs("form",{onSubmit:M,children:[e.jsxs("div",{className:"pco-org-avatar__dialog-header",children:[e.jsxs("h1",{className:"pco-org-avatar__dialog-title",children:["Church logo — ",g," mode"]}),e.jsx("button",{type:"button",onClick:()=>v.current?.close(),className:"pco-org-avatar__dialog-close","aria-label":"Close modal",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:_.smallX})})})]}),e.jsxs("div",{className:"pco-org-avatar__dialog-body",children:[u&&e.jsxs("div",{role:"alert",className:"pco-org-avatar__dialog-alert",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",className:"symbol","aria-hidden":"true",children:e.jsx("path",{d:_.exclamationTriangle})}),e.jsx("p",{children:u})]}),e.jsx(E,{accept:{"image/*":[".jpg",".jpeg",".png"]},multiple:!1,onDropAccepted:D,children:({getRootProps:h,getInputProps:s,isFocused:j,isDragAccept:N,isDragReject:k,isDragActive:C,open:R})=>{const P=W("pco-org-avatar__dialog-dropzone",`pco-org-avatar__dialog-dropzone--${g}`,{"pco-org-avatar__dialog-dropzone--image":n||m,"pco-org-avatar__dialog-dropzone--focused":j,"pco-org-avatar__dialog-dropzone--accepted":N,"pco-org-avatar__dialog-dropzone--rejected":C&&k});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{...h({className:P}),children:[e.jsx("input",{...s()}),n?e.jsx("img",{src:n.preview,alt:`Church logo for ${r}`}):m?e.jsx("img",{src:m,alt:`Church logo for ${r}`}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"64",height:"64",viewBox:"0 0 16 16","aria-hidden":"true",children:e.jsx("path",{d:_.toCloudArrow})}),C&&k?e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:"Wrong file type"}),e.jsx("p",{children:"Please upload a PNG or JPG file."})]}):e.jsxs(e.Fragment,{children:[e.jsx(z,{open:R}),e.jsx("p",{className:"pco-org-avatar__instructions-sub",children:"Use a high-quality image (up to 20mb) with a transparent background."})]})]})]}),(n||m)&&e.jsx(z,{open:R})]})}})]}),e.jsxs("div",{className:"pco-org-avatar__dialog-actions",children:[a&&g==="light"&&e.jsx(b.Button,{label:"Remove logo",kind:"secondary-delete",onClick:U,loading:i,disabled:i||l,className:"pco-org-avatar__dialog-delete"}),a&&g==="dark"&&e.jsx(b.Button,{label:"Use light mode logo",kind:"secondary",onClick:U,loading:i,disabled:i||l,className:"pco-org-avatar__dialog-delete"}),e.jsx(b.Button,{type:"button",label:"Cancel",onClick:()=>v.current?.close(),disabled:l||i}),e.jsx(b.Button,{type:"submit",label:"Update logo",kind:"primary",loading:l,disabled:!n||l||i})]})]})}),document.body)]})}function H({avatarUrl:a,darkModeAvatarUrl:r,orgName:t,onAvatarUpdate:o,pcoEnv:d,readOnly:x,showDarkModeAvatar:A=!1}){const[n,f]=c.useState(a),[l,y]=c.useState(r),i=(p,u)=>{p==="avatar"?(f(u),o?.("avatar",u)):p==="dark_mode_avatar"&&(y(u),o?.("dark_mode_avatar",u))};return e.jsxs("div",{className:"pco-org-avatars",children:[e.jsx(F,{avatarUrl:n,organization:t,mode:"avatar",pcoEnv:d,readOnly:x,onAvatarUpdate:i}),A&&e.jsx(F,{avatarUrl:l,organization:t,mode:"dark_mode_avatar",pcoEnv:d,readOnly:x,onAvatarUpdate:i,fallbackAvatarUrl:n})]})}exports.OrganizationAvatars=H;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),P=require("react-dom"),$=require("@planningcenter/url"),y=require("@planningcenter/tapestry"),I=require("@planningcenter/sweetest-alert"),x=require("@planningcenter/icons/paths/general"),L=require("@planningcenter/icons/paths/services"),E=require("react-dropzone");function B(a){var r,t,o="";if(typeof a=="string"||typeof a=="number")o+=a;else if(typeof a=="object")if(Array.isArray(a)){var d=a.length;for(r=0;r<d;r++)a[r]&&(t=B(a[r]))&&(o&&(o+=" "),o+=t)}else for(t in a)a[t]&&(o&&(o+=" "),o+=t);return o}function W(){for(var a,r,t=0,o="",d=arguments.length;t<d;t++)(a=arguments[t])&&(r=B(a))&&(o&&(o+=" "),o+=r);return o}function G(){const a=document.querySelector('meta[name="csrf-token"]');if(!a||!a.content)throw new Error('CSRF token not found. Ensure your Rails application includes <meta name="csrf-token" content="..."> in the document head.');return a.content}function J(a){const r=a.split("");return[r.shift()?.toUpperCase(),r.join("")].join("")}const X=a=>a==="dark_mode_avatar"?"dark":"light",U=({open:a})=>e.jsxs("h2",{className:"pco-org-avatar__instructions",children:["Drag & drop your logo file to upload, or"," ",e.jsx(y.Button,{label:"browse",kind:"inline-text",onClick:r=>{r.stopPropagation(),a()}})]});function z({avatarUrl:a,organization:r,mode:t,pcoEnv:o,readOnly:d,onAvatarUpdate:f,fallbackAvatarUrl:b}){const[n,_]=c.useState(null),[l,w]=c.useState(!1),[i,p]=c.useState(!1),[g,k]=c.useState(""),q=c.useId(),m=c.useRef(null),u=X(t),v=a||b,T=h=>{const[s]=h;s&&_(Object.assign(s,{preview:URL.createObjectURL(s)}))};c.useEffect(()=>()=>{n?.preview&&(URL.revokeObjectURL(n.preview),k(""))},[n]);const R=async h=>{const s=await fetch($.pcoApiUrl("accounts",{env:o}),{method:"PATCH",headers:{"Content-Type":"application/json","X-CSRF-Token":G(),Accept:"application/json"},body:JSON.stringify({data:{attributes:h}})}),j=await s.json();if(!s.ok)throw j;return j},D=async h=>{if(h.preventDefault(),!(!n||l||i)){w(!0);try{const s=new FileReader,j=await new Promise((C,N)=>{s.onloadend=()=>C(s.result),s.onerror=N,s.readAsDataURL(n)}),A=await R({[t]:j,[`${t}_cache`]:""});_(null),f(t,A.data.attributes[t].url),m.current?.close()}catch{k("We were unable to save your avatar.")}finally{w(!1)}}},S=async()=>{l||i||(p(!0),I.SweetestAlert({type:"danger",title:"Remove this logo?",content:u==="light"?"Removing this logo means no logo will appear in light mode. This cannot be undone.":b?"Removing this logo means your light mode logo will appear in dark mode. This cannot be undone.":"Removing this logo means no logo will appear in dark mode. This cannot be undone.",confirmButton:"Remove logo",onConfirm:async()=>{try{await R({[`remove_${t}`]:"1"}),f(t,""),m.current?.close()}catch{k("We were unable to delete your avatar.")}finally{p(!1)}},onCancel:()=>{p(!1)}}))},M=()=>{_(null),k("")};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pco-org-avatar",children:[e.jsx("button",{type:"button",onClick:()=>m.current?.showModal(),disabled:d,className:`pco-org-avatar__button pco-org-avatar__button--${u}`,children:v?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:v,alt:`Church logo for ${r}`}),e.jsx("div",{className:"tds-btn tds-btn--interaction tds-btn--icononly",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:x.pencil})})})]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"48",height:"48",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:L.image})}),e.jsx("div",{className:"tds-btn tds-btn--interaction tds-btn--icononly",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:x.pencil})})})]})}),e.jsxs("div",{className:"pco-org-avatar__label",children:[J(u)," mode"]})]}),P.createPortal(e.jsx("dialog",{id:q,ref:m,className:"pco-org-avatar__dialog",onClose:M,children:e.jsxs("form",{onSubmit:D,children:[e.jsxs("div",{className:"pco-org-avatar__dialog-header",children:[e.jsxs("h1",{className:"pco-org-avatar__dialog-title",children:["Church logo — ",u," mode"]}),e.jsx("button",{type:"button",onClick:()=>m.current?.close(),className:"pco-org-avatar__dialog-close","aria-label":"Close modal",children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:x.smallX})})})]}),e.jsxs("div",{className:"pco-org-avatar__dialog-body",children:[g&&e.jsxs("div",{role:"alert",className:"pco-org-avatar-alert pco-org-avatar__dialog-alert",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",className:"symbol","aria-hidden":"true",children:e.jsx("path",{d:x.exclamationTriangle})}),e.jsx("p",{children:g})]}),e.jsx(E,{accept:{"image/*":[".jpg",".jpeg",".png"]},multiple:!1,onDropAccepted:T,children:({getRootProps:h,getInputProps:s,isFocused:j,isDragAccept:A,isDragReject:C,isDragActive:N,open:F})=>{const O=W("pco-org-avatar__dialog-dropzone",`pco-org-avatar__dialog-dropzone--${u}`,{"pco-org-avatar__dialog-dropzone--image":n||v,"pco-org-avatar__dialog-dropzone--focused":j,"pco-org-avatar__dialog-dropzone--accepted":A,"pco-org-avatar__dialog-dropzone--rejected":N&&C});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{...h({className:O}),children:[e.jsx("input",{...s()}),n?e.jsx("img",{src:n.preview,alt:`Church logo for ${r}`}):v?e.jsx("img",{src:v,alt:`Church logo for ${r}`}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"64",height:"64",viewBox:"0 0 16 16","aria-hidden":"true",children:e.jsx("path",{d:x.toCloudArrow})}),N&&C?e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:"Wrong file type"}),e.jsx("p",{children:"Please upload a PNG or JPG file."})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{open:F}),e.jsx("p",{className:"pco-org-avatar__instructions-sub",children:"Use a high-quality image (up to 20mb) with a transparent background."})]})]})]}),(n||v)&&e.jsx(U,{open:F})]})}})]}),e.jsxs("div",{className:"pco-org-avatar__dialog-actions",children:[a&&u==="light"&&e.jsx(y.Button,{label:"Remove logo",kind:"secondary-delete",onClick:S,loading:i,disabled:i||l,className:"pco-org-avatar__dialog-delete"}),a&&u==="dark"&&e.jsx(y.Button,{label:"Use light mode logo",kind:"secondary",onClick:S,loading:i,disabled:i||l,className:"pco-org-avatar__dialog-delete"}),e.jsx(y.Button,{type:"button",label:"Cancel",onClick:()=>m.current?.close(),disabled:l||i}),e.jsx(y.Button,{type:"submit",label:"Update logo",kind:"primary",loading:l,disabled:!n||l||i})]})]})}),document.body)]})}function H({avatarUrl:a,darkModeAvatarUrl:r,orgName:t,onAvatarUpdate:o,pcoEnv:d,readOnly:f,showDarkModeAvatar:b=!1}){const[n,_]=c.useState(a),[l,w]=c.useState(r),i=(p,g)=>{p==="avatar"?(_(g),o?.("avatar",g)):p==="dark_mode_avatar"&&(w(g),o?.("dark_mode_avatar",g))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pco-org-avatars",children:[e.jsx(z,{avatarUrl:n,organization:t,mode:"avatar",pcoEnv:d,readOnly:f,onAvatarUpdate:i}),b&&e.jsx(z,{avatarUrl:l,organization:t,mode:"dark_mode_avatar",pcoEnv:d,readOnly:f,onAvatarUpdate:i,fallbackAvatarUrl:n})]}),b&&n&&!l&&e.jsxs("div",{className:"pco-org-avatar-alert",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",className:"symbol","aria-hidden":"true",children:e.jsx("path",{d:x.infoCircle})}),e.jsx("p",{children:"The same logo is being used for both light and dark modes."})]})]})}exports.OrganizationAvatars=H;
package/dist/index.js CHANGED
@@ -1,63 +1,63 @@
1
- import { jsxs as n, Fragment as u, jsx as a } from "react/jsx-runtime";
2
- import { useState as b, useId as L, useRef as E, useEffect as W } from "react";
1
+ import { jsxs as r, Fragment as h, jsx as e } from "react/jsx-runtime";
2
+ import { useState as _, useId as L, useRef as E, useEffect as W } from "react";
3
3
  import { createPortal as q } from "react-dom";
4
4
  import { pcoApiUrl as G } from "@planningcenter/url";
5
- import { Button as k } from "@planningcenter/tapestry";
5
+ import { Button as C } from "@planningcenter/tapestry";
6
6
  import { SweetestAlert as J } from "@planningcenter/sweetest-alert";
7
- import { pencil as B, smallX as X, exclamationTriangle as H, toCloudArrow as K } from "@planningcenter/icons/paths/general";
8
- import { image as Q } from "@planningcenter/icons/paths/services";
9
- import V from "react-dropzone";
10
- function M(e) {
11
- var o, r, t = "";
12
- if (typeof e == "string" || typeof e == "number") t += e;
13
- else if (typeof e == "object") if (Array.isArray(e)) {
14
- var s = e.length;
15
- for (o = 0; o < s; o++) e[o] && (r = M(e[o])) && (t && (t += " "), t += r);
16
- } else for (r in e) e[r] && (t && (t += " "), t += r);
17
- return t;
18
- }
19
- function Y() {
20
- for (var e, o, r = 0, t = "", s = arguments.length; r < s; r++) (e = arguments[r]) && (o = M(e)) && (t && (t += " "), t += o);
21
- return t;
7
+ import { pencil as T, smallX as X, exclamationTriangle as H, toCloudArrow as K, infoCircle as Q } from "@planningcenter/icons/paths/general";
8
+ import { image as V } from "@planningcenter/icons/paths/services";
9
+ import Y from "react-dropzone";
10
+ function D(a) {
11
+ var t, o, n = "";
12
+ if (typeof a == "string" || typeof a == "number") n += a;
13
+ else if (typeof a == "object") if (Array.isArray(a)) {
14
+ var s = a.length;
15
+ for (t = 0; t < s; t++) a[t] && (o = D(a[t])) && (n && (n += " "), n += o);
16
+ } else for (o in a) a[o] && (n && (n += " "), n += o);
17
+ return n;
22
18
  }
23
19
  function Z() {
24
- const e = document.querySelector('meta[name="csrf-token"]');
25
- if (!e || !e.content)
20
+ for (var a, t, o = 0, n = "", s = arguments.length; o < s; o++) (a = arguments[o]) && (t = D(a)) && (n && (n += " "), n += t);
21
+ return n;
22
+ }
23
+ function ee() {
24
+ const a = document.querySelector('meta[name="csrf-token"]');
25
+ if (!a || !a.content)
26
26
  throw new Error(
27
27
  'CSRF token not found. Ensure your Rails application includes <meta name="csrf-token" content="..."> in the document head.'
28
28
  );
29
- return e.content;
29
+ return a.content;
30
30
  }
31
- function aa(e) {
32
- const o = e.split("");
33
- return [o.shift()?.toUpperCase(), o.join("")].join("");
31
+ function ae(a) {
32
+ const t = a.split("");
33
+ return [t.shift()?.toUpperCase(), t.join("")].join("");
34
34
  }
35
- const ea = (e) => e === "dark_mode_avatar" ? "dark" : "light", D = ({ open: e }) => /* @__PURE__ */ n("h2", { className: "pco-org-avatar__instructions", children: [
35
+ const oe = (a) => a === "dark_mode_avatar" ? "dark" : "light", B = ({ open: a }) => /* @__PURE__ */ r("h2", { className: "pco-org-avatar__instructions", children: [
36
36
  "Drag & drop your logo file to upload, or",
37
37
  " ",
38
- /* @__PURE__ */ a(
39
- k,
38
+ /* @__PURE__ */ e(
39
+ C,
40
40
  {
41
41
  label: "browse",
42
42
  kind: "inline-text",
43
- onClick: (o) => {
44
- o.stopPropagation(), e();
43
+ onClick: (t) => {
44
+ t.stopPropagation(), a();
45
45
  }
46
46
  }
47
47
  )
48
48
  ] });
49
49
  function F({
50
- avatarUrl: e,
51
- organization: o,
52
- mode: r,
53
- pcoEnv: t,
50
+ avatarUrl: a,
51
+ organization: t,
52
+ mode: o,
53
+ pcoEnv: n,
54
54
  readOnly: s,
55
55
  onAvatarUpdate: y,
56
- fallbackAvatarUrl: R
56
+ fallbackAvatarUrl: w
57
57
  }) {
58
- const [i, w] = b(null), [d, C] = b(!1), [c, m] = b(!1), [g, A] = b(""), $ = L(), v = E(null), h = ea(r), f = e || R, P = (p) => {
59
- const [l] = p;
60
- l && w(
58
+ const [i, k] = _(null), [d, N] = _(!1), [c, m] = _(!1), [g, A] = _(""), M = L(), v = E(null), p = oe(o), f = a || w, P = (u) => {
59
+ const [l] = u;
60
+ l && k(
61
61
  Object.assign(l, {
62
62
  preview: URL.createObjectURL(l)
63
63
  })
@@ -66,50 +66,50 @@ function F({
66
66
  W(() => () => {
67
67
  i?.preview && (URL.revokeObjectURL(i.preview), A(""));
68
68
  }, [i]);
69
- const z = async (p) => {
70
- const l = await fetch(G("accounts", { env: t }), {
69
+ const x = async (u) => {
70
+ const l = await fetch(G("accounts", { env: n }), {
71
71
  method: "PATCH",
72
72
  headers: {
73
73
  "Content-Type": "application/json",
74
- "X-CSRF-Token": Z(),
74
+ "X-CSRF-Token": ee(),
75
75
  Accept: "application/json"
76
76
  },
77
77
  body: JSON.stringify({
78
78
  data: {
79
- attributes: p
79
+ attributes: u
80
80
  }
81
81
  })
82
- }), _ = await l.json();
83
- if (!l.ok) throw _;
84
- return _;
85
- }, T = async (p) => {
86
- if (p.preventDefault(), !(!i || d || c)) {
87
- C(!0);
82
+ }), b = await l.json();
83
+ if (!l.ok) throw b;
84
+ return b;
85
+ }, $ = async (u) => {
86
+ if (u.preventDefault(), !(!i || d || c)) {
87
+ N(!0);
88
88
  try {
89
- const l = new FileReader(), _ = await new Promise((N, U) => {
90
- l.onloadend = () => N(l.result), l.onerror = U, l.readAsDataURL(i);
91
- }), j = await z({
92
- [r]: _,
93
- [`${r}_cache`]: ""
89
+ const l = new FileReader(), b = await new Promise((R, U) => {
90
+ l.onloadend = () => R(l.result), l.onerror = U, l.readAsDataURL(i);
91
+ }), j = await x({
92
+ [o]: b,
93
+ [`${o}_cache`]: ""
94
94
  });
95
- w(null), y(r, j.data.attributes[r].url), v.current?.close();
95
+ k(null), y(o, j.data.attributes[o].url), v.current?.close();
96
96
  } catch {
97
97
  A("We were unable to save your avatar.");
98
98
  } finally {
99
- C(!1);
99
+ N(!1);
100
100
  }
101
101
  }
102
- }, x = async () => {
102
+ }, z = async () => {
103
103
  d || c || (m(!0), J({
104
104
  type: "danger",
105
105
  title: "Remove this logo?",
106
- content: `Removing this logo will mean your light mode logo appear in ${h} mode. This cannot be undone.`,
106
+ content: p === "light" ? "Removing this logo means no logo will appear in light mode. This cannot be undone." : w ? "Removing this logo means your light mode logo will appear in dark mode. This cannot be undone." : "Removing this logo means no logo will appear in dark mode. This cannot be undone.",
107
107
  confirmButton: "Remove logo",
108
108
  onConfirm: async () => {
109
109
  try {
110
- await z({
111
- [`remove_${r}`]: "1"
112
- }), y(r, ""), v.current?.close();
110
+ await x({
111
+ [`remove_${o}`]: "1"
112
+ }), y(o, ""), v.current?.close();
113
113
  } catch {
114
114
  A("We were unable to delete your avatar.");
115
115
  } finally {
@@ -121,20 +121,20 @@ function F({
121
121
  }
122
122
  }));
123
123
  }, O = () => {
124
- w(null), A("");
124
+ k(null), A("");
125
125
  };
126
- return /* @__PURE__ */ n(u, { children: [
127
- /* @__PURE__ */ n("div", { className: "pco-org-avatar", children: [
128
- /* @__PURE__ */ a(
126
+ return /* @__PURE__ */ r(h, { children: [
127
+ /* @__PURE__ */ r("div", { className: "pco-org-avatar", children: [
128
+ /* @__PURE__ */ e(
129
129
  "button",
130
130
  {
131
131
  type: "button",
132
132
  onClick: () => v.current?.showModal(),
133
133
  disabled: s,
134
- className: `pco-org-avatar__button pco-org-avatar__button--${h}`,
135
- children: f ? /* @__PURE__ */ n(u, { children: [
136
- /* @__PURE__ */ a("img", { src: f, alt: `Church logo for ${o}` }),
137
- /* @__PURE__ */ a("div", { className: "tds-btn tds-btn--interaction tds-btn--icononly", children: /* @__PURE__ */ a(
134
+ className: `pco-org-avatar__button pco-org-avatar__button--${p}`,
135
+ children: f ? /* @__PURE__ */ r(h, { children: [
136
+ /* @__PURE__ */ e("img", { src: f, alt: `Church logo for ${t}` }),
137
+ /* @__PURE__ */ e("div", { className: "tds-btn tds-btn--interaction tds-btn--icononly", children: /* @__PURE__ */ e(
138
138
  "svg",
139
139
  {
140
140
  width: "14",
@@ -142,11 +142,11 @@ function F({
142
142
  viewBox: "0 0 16 16",
143
143
  fill: "currentColor",
144
144
  "aria-hidden": "true",
145
- children: /* @__PURE__ */ a("path", { d: B })
145
+ children: /* @__PURE__ */ e("path", { d: T })
146
146
  }
147
147
  ) })
148
- ] }) : /* @__PURE__ */ n(u, { children: [
149
- /* @__PURE__ */ a(
148
+ ] }) : /* @__PURE__ */ r(h, { children: [
149
+ /* @__PURE__ */ e(
150
150
  "svg",
151
151
  {
152
152
  width: "48",
@@ -154,10 +154,10 @@ function F({
154
154
  viewBox: "0 0 16 16",
155
155
  fill: "currentColor",
156
156
  "aria-hidden": "true",
157
- children: /* @__PURE__ */ a("path", { d: Q })
157
+ children: /* @__PURE__ */ e("path", { d: V })
158
158
  }
159
159
  ),
160
- /* @__PURE__ */ a("div", { className: "tds-btn tds-btn--interaction tds-btn--icononly", children: /* @__PURE__ */ a(
160
+ /* @__PURE__ */ e("div", { className: "tds-btn tds-btn--interaction tds-btn--icononly", children: /* @__PURE__ */ e(
161
161
  "svg",
162
162
  {
163
163
  width: "14",
@@ -165,40 +165,40 @@ function F({
165
165
  viewBox: "0 0 16 16",
166
166
  fill: "currentColor",
167
167
  "aria-hidden": "true",
168
- children: /* @__PURE__ */ a("path", { d: B })
168
+ children: /* @__PURE__ */ e("path", { d: T })
169
169
  }
170
170
  ) })
171
171
  ] })
172
172
  }
173
173
  ),
174
- /* @__PURE__ */ n("div", { className: "pco-org-avatar__label", children: [
175
- aa(h),
174
+ /* @__PURE__ */ r("div", { className: "pco-org-avatar__label", children: [
175
+ ae(p),
176
176
  " mode"
177
177
  ] })
178
178
  ] }),
179
179
  q(
180
- /* @__PURE__ */ a(
180
+ /* @__PURE__ */ e(
181
181
  "dialog",
182
182
  {
183
- id: $,
183
+ id: M,
184
184
  ref: v,
185
185
  className: "pco-org-avatar__dialog",
186
186
  onClose: O,
187
- children: /* @__PURE__ */ n("form", { onSubmit: T, children: [
188
- /* @__PURE__ */ n("div", { className: "pco-org-avatar__dialog-header", children: [
189
- /* @__PURE__ */ n("h1", { className: "pco-org-avatar__dialog-title", children: [
187
+ children: /* @__PURE__ */ r("form", { onSubmit: $, children: [
188
+ /* @__PURE__ */ r("div", { className: "pco-org-avatar__dialog-header", children: [
189
+ /* @__PURE__ */ r("h1", { className: "pco-org-avatar__dialog-title", children: [
190
190
  "Church logo — ",
191
- h,
191
+ p,
192
192
  " mode"
193
193
  ] }),
194
- /* @__PURE__ */ a(
194
+ /* @__PURE__ */ e(
195
195
  "button",
196
196
  {
197
197
  type: "button",
198
198
  onClick: () => v.current?.close(),
199
199
  className: "pco-org-avatar__dialog-close",
200
200
  "aria-label": "Close modal",
201
- children: /* @__PURE__ */ a(
201
+ children: /* @__PURE__ */ e(
202
202
  "svg",
203
203
  {
204
204
  width: "16",
@@ -206,15 +206,15 @@ function F({
206
206
  viewBox: "0 0 16 16",
207
207
  fill: "currentColor",
208
208
  "aria-hidden": "true",
209
- children: /* @__PURE__ */ a("path", { d: X })
209
+ children: /* @__PURE__ */ e("path", { d: X })
210
210
  }
211
211
  )
212
212
  }
213
213
  )
214
214
  ] }),
215
- /* @__PURE__ */ n("div", { className: "pco-org-avatar__dialog-body", children: [
216
- g && /* @__PURE__ */ n("div", { role: "alert", className: "pco-org-avatar__dialog-alert", children: [
217
- /* @__PURE__ */ a(
215
+ /* @__PURE__ */ r("div", { className: "pco-org-avatar__dialog-body", children: [
216
+ g && /* @__PURE__ */ r("div", { role: "alert", className: "pco-org-avatar-alert pco-org-avatar__dialog-alert", children: [
217
+ /* @__PURE__ */ e(
218
218
  "svg",
219
219
  {
220
220
  width: "16",
@@ -222,102 +222,102 @@ function F({
222
222
  viewBox: "0 0 16 16",
223
223
  className: "symbol",
224
224
  "aria-hidden": "true",
225
- children: /* @__PURE__ */ a("path", { d: H })
225
+ children: /* @__PURE__ */ e("path", { d: H })
226
226
  }
227
227
  ),
228
- /* @__PURE__ */ a("p", { children: g })
228
+ /* @__PURE__ */ e("p", { children: g })
229
229
  ] }),
230
- /* @__PURE__ */ a(
231
- V,
230
+ /* @__PURE__ */ e(
231
+ Y,
232
232
  {
233
233
  accept: { "image/*": [".jpg", ".jpeg", ".png"] },
234
234
  multiple: !1,
235
235
  onDropAccepted: P,
236
236
  children: ({
237
- getRootProps: p,
237
+ getRootProps: u,
238
238
  getInputProps: l,
239
- isFocused: _,
239
+ isFocused: b,
240
240
  isDragAccept: j,
241
- isDragReject: N,
241
+ isDragReject: R,
242
242
  isDragActive: U,
243
243
  open: S
244
244
  }) => {
245
- const I = Y(
245
+ const I = Z(
246
246
  "pco-org-avatar__dialog-dropzone",
247
- `pco-org-avatar__dialog-dropzone--${h}`,
247
+ `pco-org-avatar__dialog-dropzone--${p}`,
248
248
  {
249
249
  "pco-org-avatar__dialog-dropzone--image": i || f,
250
- "pco-org-avatar__dialog-dropzone--focused": _,
250
+ "pco-org-avatar__dialog-dropzone--focused": b,
251
251
  "pco-org-avatar__dialog-dropzone--accepted": j,
252
- "pco-org-avatar__dialog-dropzone--rejected": U && N
252
+ "pco-org-avatar__dialog-dropzone--rejected": U && R
253
253
  }
254
254
  );
255
- return /* @__PURE__ */ n(u, { children: [
256
- /* @__PURE__ */ n("div", { ...p({ className: I }), children: [
257
- /* @__PURE__ */ a("input", { ...l() }),
258
- i ? /* @__PURE__ */ a(
255
+ return /* @__PURE__ */ r(h, { children: [
256
+ /* @__PURE__ */ r("div", { ...u({ className: I }), children: [
257
+ /* @__PURE__ */ e("input", { ...l() }),
258
+ i ? /* @__PURE__ */ e(
259
259
  "img",
260
260
  {
261
261
  src: i.preview,
262
- alt: `Church logo for ${o}`
262
+ alt: `Church logo for ${t}`
263
263
  }
264
- ) : f ? /* @__PURE__ */ a(
264
+ ) : f ? /* @__PURE__ */ e(
265
265
  "img",
266
266
  {
267
267
  src: f,
268
- alt: `Church logo for ${o}`
268
+ alt: `Church logo for ${t}`
269
269
  }
270
- ) : /* @__PURE__ */ n(u, { children: [
271
- /* @__PURE__ */ a(
270
+ ) : /* @__PURE__ */ r(h, { children: [
271
+ /* @__PURE__ */ e(
272
272
  "svg",
273
273
  {
274
274
  width: "64",
275
275
  height: "64",
276
276
  viewBox: "0 0 16 16",
277
277
  "aria-hidden": "true",
278
- children: /* @__PURE__ */ a("path", { d: K })
278
+ children: /* @__PURE__ */ e("path", { d: K })
279
279
  }
280
280
  ),
281
- U && N ? /* @__PURE__ */ n(u, { children: [
282
- /* @__PURE__ */ a("h2", { children: "Wrong file type" }),
283
- /* @__PURE__ */ a("p", { children: "Please upload a PNG or JPG file." })
284
- ] }) : /* @__PURE__ */ n(u, { children: [
285
- /* @__PURE__ */ a(D, { open: S }),
286
- /* @__PURE__ */ a("p", { className: "pco-org-avatar__instructions-sub", children: "Use a high-quality image (up to 20mb) with a transparent background." })
281
+ U && R ? /* @__PURE__ */ r(h, { children: [
282
+ /* @__PURE__ */ e("h2", { children: "Wrong file type" }),
283
+ /* @__PURE__ */ e("p", { children: "Please upload a PNG or JPG file." })
284
+ ] }) : /* @__PURE__ */ r(h, { children: [
285
+ /* @__PURE__ */ e(B, { open: S }),
286
+ /* @__PURE__ */ e("p", { className: "pco-org-avatar__instructions-sub", children: "Use a high-quality image (up to 20mb) with a transparent background." })
287
287
  ] })
288
288
  ] })
289
289
  ] }),
290
- (i || f) && /* @__PURE__ */ a(D, { open: S })
290
+ (i || f) && /* @__PURE__ */ e(B, { open: S })
291
291
  ] });
292
292
  }
293
293
  }
294
294
  )
295
295
  ] }),
296
- /* @__PURE__ */ n("div", { className: "pco-org-avatar__dialog-actions", children: [
297
- e && h === "light" && /* @__PURE__ */ a(
298
- k,
296
+ /* @__PURE__ */ r("div", { className: "pco-org-avatar__dialog-actions", children: [
297
+ a && p === "light" && /* @__PURE__ */ e(
298
+ C,
299
299
  {
300
300
  label: "Remove logo",
301
301
  kind: "secondary-delete",
302
- onClick: x,
302
+ onClick: z,
303
303
  loading: c,
304
304
  disabled: c || d,
305
305
  className: "pco-org-avatar__dialog-delete"
306
306
  }
307
307
  ),
308
- e && h === "dark" && /* @__PURE__ */ a(
309
- k,
308
+ a && p === "dark" && /* @__PURE__ */ e(
309
+ C,
310
310
  {
311
311
  label: "Use light mode logo",
312
312
  kind: "secondary",
313
- onClick: x,
313
+ onClick: z,
314
314
  loading: c,
315
315
  disabled: c || d,
316
316
  className: "pco-org-avatar__dialog-delete"
317
317
  }
318
318
  ),
319
- /* @__PURE__ */ a(
320
- k,
319
+ /* @__PURE__ */ e(
320
+ C,
321
321
  {
322
322
  type: "button",
323
323
  label: "Cancel",
@@ -325,8 +325,8 @@ function F({
325
325
  disabled: d || c
326
326
  }
327
327
  ),
328
- /* @__PURE__ */ a(
329
- k,
328
+ /* @__PURE__ */ e(
329
+ C,
330
330
  {
331
331
  type: "submit",
332
332
  label: "Update logo",
@@ -343,46 +343,62 @@ function F({
343
343
  )
344
344
  ] });
345
345
  }
346
- function ga({
347
- avatarUrl: e,
348
- darkModeAvatarUrl: o,
349
- orgName: r,
350
- onAvatarUpdate: t,
346
+ function ge({
347
+ avatarUrl: a,
348
+ darkModeAvatarUrl: t,
349
+ orgName: o,
350
+ onAvatarUpdate: n,
351
351
  pcoEnv: s,
352
352
  readOnly: y,
353
- showDarkModeAvatar: R = !1
353
+ showDarkModeAvatar: w = !1
354
354
  }) {
355
- const [i, w] = b(e), [d, C] = b(
356
- o
355
+ const [i, k] = _(a), [d, N] = _(
356
+ t
357
357
  ), c = (m, g) => {
358
- m === "avatar" ? (w(g), t?.("avatar", g)) : m === "dark_mode_avatar" && (C(g), t?.("dark_mode_avatar", g));
358
+ m === "avatar" ? (k(g), n?.("avatar", g)) : m === "dark_mode_avatar" && (N(g), n?.("dark_mode_avatar", g));
359
359
  };
360
- return /* @__PURE__ */ n("div", { className: "pco-org-avatars", children: [
361
- /* @__PURE__ */ a(
362
- F,
363
- {
364
- avatarUrl: i,
365
- organization: r,
366
- mode: "avatar",
367
- pcoEnv: s,
368
- readOnly: y,
369
- onAvatarUpdate: c
370
- }
371
- ),
372
- R && /* @__PURE__ */ a(
373
- F,
374
- {
375
- avatarUrl: d,
376
- organization: r,
377
- mode: "dark_mode_avatar",
378
- pcoEnv: s,
379
- readOnly: y,
380
- onAvatarUpdate: c,
381
- fallbackAvatarUrl: i
382
- }
383
- )
360
+ return /* @__PURE__ */ r(h, { children: [
361
+ /* @__PURE__ */ r("div", { className: "pco-org-avatars", children: [
362
+ /* @__PURE__ */ e(
363
+ F,
364
+ {
365
+ avatarUrl: i,
366
+ organization: o,
367
+ mode: "avatar",
368
+ pcoEnv: s,
369
+ readOnly: y,
370
+ onAvatarUpdate: c
371
+ }
372
+ ),
373
+ w && /* @__PURE__ */ e(
374
+ F,
375
+ {
376
+ avatarUrl: d,
377
+ organization: o,
378
+ mode: "dark_mode_avatar",
379
+ pcoEnv: s,
380
+ readOnly: y,
381
+ onAvatarUpdate: c,
382
+ fallbackAvatarUrl: i
383
+ }
384
+ )
385
+ ] }),
386
+ w && i && !d && /* @__PURE__ */ r("div", { className: "pco-org-avatar-alert", children: [
387
+ /* @__PURE__ */ e(
388
+ "svg",
389
+ {
390
+ width: "16",
391
+ height: "16",
392
+ viewBox: "0 0 16 16",
393
+ className: "symbol",
394
+ "aria-hidden": "true",
395
+ children: /* @__PURE__ */ e("path", { d: Q })
396
+ }
397
+ ),
398
+ /* @__PURE__ */ e("p", { children: "The same logo is being used for both light and dark modes." })
399
+ ] })
384
400
  ] });
385
401
  }
386
402
  export {
387
- ga as OrganizationAvatars
403
+ ge as OrganizationAvatars
388
404
  };
package/dist/style.css CHANGED
@@ -3,23 +3,52 @@
3
3
  gap: var(--t-spacing-1);
4
4
  }
5
5
 
6
+ .pco-org-avatar-alert {
7
+ align-items: center;
8
+ background: var(--t-fill-color-status-info-ghost);
9
+ border-radius: var(--t-border-radius-lg);
10
+ display: flex;
11
+ gap: var(--t-spacing-2);
12
+ margin-top: var(--t-spacing-2);
13
+ padding: var(--t-spacing-2);
14
+ }
15
+
16
+ .pco-org-avatar-alert svg {
17
+ fill: var(--t-icon-color-status-info);
18
+ flex-shrink: 0;
19
+ height: var(--t-element-size-md);
20
+ width: var(--t-element-size-md);
21
+ }
22
+
23
+ .pco-org-avatar-alert p {
24
+ display: flex;
25
+ flex-direction: column;
26
+ gap: var(--t-spacing-half);
27
+ margin: 0;
28
+ }
29
+
6
30
  .pco-org-avatar {
7
31
  align-items: center;
8
- display: inline-flex;
32
+ display: flex;
9
33
  flex-direction: column;
10
34
  gap: var(--t-spacing-1);
35
+ flex: 1;
36
+ max-width: 175px;
37
+ min-width: 0;
11
38
  }
12
39
 
13
40
  .pco-org-avatar__button {
41
+ aspect-ratio: 175 / 100;
14
42
  background: var(--t-surface-color-canvas);
15
43
  border: var(--t-border-width) dashed var(--t-border-color);
16
44
  border-radius: var(--t-border-radius-lg);
17
45
  color: var(--t-icon-color-dim);
18
46
  cursor: pointer;
19
- height: 100px;
47
+ max-height: 100px;
48
+ max-width: 100%;
20
49
  padding: var(--t-spacing-1);
21
50
  position: relative;
22
- width: 175px;
51
+ width: 100%;
23
52
  }
24
53
 
25
54
  .pco-org-avatar__button img {
@@ -136,27 +165,11 @@
136
165
 
137
166
  .pco-org-avatar__dialog-alert {
138
167
  background: var(--t-fill-color-status-error-ghost);
139
- border-radius: var(--t-border-radius-lg);
140
- display: flex;
141
- gap: var(--t-spacing-2);
142
- margin-bottom: var(--t-spacing-2);
143
- padding: var(--t-spacing-2);
168
+ margin-block: 0 var(--t-spacing-2);
144
169
  }
145
170
 
146
171
  .pco-org-avatar__dialog-alert svg {
147
172
  fill: var(--t-icon-color-status-error);
148
- flex-shrink: 0;
149
- height: var(--t-element-size-md);
150
- position: relative;
151
- top: 1px;
152
- width: var(--t-element-size-md);
153
- }
154
-
155
- .pco-org-avatar__dialog-alert p {
156
- display: flex;
157
- flex-direction: column;
158
- gap: var(--t-spacing-half);
159
- margin: 0;
160
173
  }
161
174
 
162
175
  .pco-org-avatar__dialog-dropzone {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/organization-avatars",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Organization avatar upload components for Planning Center apps",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.22",