@withone/connect 0.12.0 → 0.12.2

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/src/react.ts CHANGED
@@ -10,8 +10,8 @@ import type { CSSProperties, ReactElement } from "react";
10
10
 
11
11
  import {
12
12
  createConnectFlow,
13
- mountConnectButton,
14
13
  readConnectReturn,
14
+ renderConnectButton,
15
15
  type ConnectButtonHandle,
16
16
  type ConnectButtonProps as ConnectButtonCoreProps,
17
17
  type ConnectFailureCode,
@@ -20,7 +20,7 @@ import {
20
20
  } from "@withone/connect";
21
21
 
22
22
  export interface ConnectButtonProps extends ConnectButtonCoreProps {
23
- /** On the wrapper element around the button. */
23
+ /** On the host element, `<span class="one-connect">`. */
24
24
  className?: string;
25
25
  style?: CSSProperties;
26
26
  }
@@ -45,7 +45,7 @@ const visualKey = (props: ConnectButtonCoreProps): string =>
45
45
  ]);
46
46
 
47
47
  export function ConnectButton(props: ConnectButtonProps): ReactElement {
48
- const containerRef = useRef<HTMLDivElement | null>(null);
48
+ const hostRef = useRef<HTMLSpanElement | null>(null);
49
49
  const handleRef = useRef<ConnectButtonHandle | null>(null);
50
50
  const keyRef = useRef<string>("");
51
51
  const latest = useRef(props);
@@ -59,9 +59,9 @@ export function ConnectButton(props: ConnectButtonProps): ReactElement {
59
59
  });
60
60
 
61
61
  useEffect(() => {
62
- if (!containerRef.current) return;
63
- handleRef.current = mountConnectButton(
64
- containerRef.current,
62
+ if (!hostRef.current) return;
63
+ handleRef.current = renderConnectButton(
64
+ hostRef.current,
65
65
  withLatestCallbacks(),
66
66
  );
67
67
  keyRef.current = visualKey(latest.current);
@@ -81,10 +81,17 @@ export function ConnectButton(props: ConnectButtonProps): ReactElement {
81
81
  // eslint-disable-next-line react-hooks/exhaustive-deps
82
82
  }, [key]);
83
83
 
84
- return createElement("div", {
85
- ref: containerRef,
86
- className: props.className,
84
+ // The host is rendered here, layout attributes included, so the server
85
+ // HTML and the hydrated element agree; the button lives in its shadow
86
+ // root, which React never sees.
87
+ return createElement("span", {
88
+ ref: hostRef,
89
+ className: props.className
90
+ ? `one-connect ${props.className}`
91
+ : "one-connect",
87
92
  style: props.style,
93
+ "data-variant": props.variant ?? "default",
94
+ "data-full-width": props.fullWidth ? "" : undefined,
88
95
  });
89
96
  }
90
97
 
package/src/vue.ts CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  import type { PropType } from "vue";
22
22
 
23
23
  import {
24
- mountConnectButton,
24
+ renderConnectButton,
25
25
  type ConnectButtonHandle,
26
26
  type ConnectButtonPlatformInput,
27
27
  type ConnectButtonProps,
@@ -71,7 +71,7 @@ export const ConnectButton = defineComponent({
71
71
  cancel: () => true,
72
72
  },
73
73
  setup(props, { emit }) {
74
- const container = ref<HTMLElement | null>(null);
74
+ const host = ref<HTMLElement | null>(null);
75
75
  let handle: ConnectButtonHandle | null = null;
76
76
 
77
77
  const current = (): ConnectButtonProps => ({
@@ -82,8 +82,7 @@ export const ConnectButton = defineComponent({
82
82
  });
83
83
 
84
84
  onMounted(() => {
85
- if (container.value)
86
- handle = mountConnectButton(container.value, current());
85
+ if (host.value) handle = renderConnectButton(host.value, current());
87
86
  });
88
87
  watch(
89
88
  () => ({ ...props }),
@@ -95,6 +94,14 @@ export const ConnectButton = defineComponent({
95
94
  handle = null;
96
95
  });
97
96
 
98
- return () => h("div", { ref: container });
97
+ // The host carries its layout attributes from the render, so server
98
+ // and client HTML agree; the button lives in its shadow root.
99
+ return () =>
100
+ h("span", {
101
+ ref: host,
102
+ class: "one-connect",
103
+ "data-variant": props.variant ?? "default",
104
+ "data-full-width": props.fullWidth ? "" : undefined,
105
+ });
99
106
  },
100
107
  });