@zag-js/avatar
Advanced tools
Comparing version 0.0.0-dev-20230713105642 to 0.0.0-dev-20230713124852
import * as _zag_js_anatomy from '@zag-js/anatomy'; | ||
import { RequiredBy, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types'; | ||
import { PropTypes, RequiredBy, CommonProperties, Context, NormalizeProps } from '@zag-js/types'; | ||
import * as _zag_js_core from '@zag-js/core'; | ||
@@ -12,13 +12,3 @@ import { StateMachine } from '@zag-js/core'; | ||
}; | ||
type PrivateContext = Context<{}>; | ||
type ComputedContext = Readonly<{}>; | ||
type UserDefinedContext = RequiredBy<PublicContext, "id">; | ||
type MachineContext = PublicContext & PrivateContext & ComputedContext; | ||
type MachineState = { | ||
value: "loading" | "error" | "loaded"; | ||
}; | ||
type State = StateMachine.State<MachineContext, MachineState>; | ||
type Send = StateMachine.Send<StateMachine.AnyEventObject>; | ||
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): { | ||
type PublicApi<T extends PropTypes = PropTypes> = { | ||
/** | ||
@@ -48,5 +38,16 @@ * Whether the image is loaded. | ||
}; | ||
type PrivateContext = Context<{}>; | ||
type ComputedContext = Readonly<{}>; | ||
type UserDefinedContext = RequiredBy<PublicContext, "id">; | ||
type MachineContext = PublicContext & PrivateContext & ComputedContext; | ||
type MachineState = { | ||
value: "loading" | "error" | "loaded"; | ||
}; | ||
type State = StateMachine.State<MachineContext, MachineState>; | ||
type Send = StateMachine.Send<StateMachine.AnyEventObject>; | ||
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): PublicApi<T>; | ||
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>; | ||
export { UserDefinedContext as Context, anatomy, connect, machine }; | ||
export { UserDefinedContext as Context, PublicApi, anatomy, connect, machine }; |
@@ -52,25 +52,10 @@ "use strict"; | ||
return { | ||
/** | ||
* Whether the image is loaded. | ||
*/ | ||
isLoaded, | ||
/** | ||
* Whether the fallback is shown. | ||
*/ | ||
showFallback, | ||
/** | ||
* Function to set new src. | ||
*/ | ||
setSrc(src) { | ||
send({ type: "SRC.SET", src }); | ||
}, | ||
/** | ||
* Function to set loaded state. | ||
*/ | ||
setLoaded() { | ||
send({ type: "IMG.LOADED", src: "api" }); | ||
}, | ||
/** | ||
* Function to set error state. | ||
*/ | ||
setError() { | ||
@@ -77,0 +62,0 @@ send({ type: "IMG.ERROR", src: "api" }); |
{ | ||
"name": "@zag-js/avatar", | ||
"version": "0.0.0-dev-20230713105642", | ||
"version": "0.0.0-dev-20230713124852", | ||
"description": "Core logic for the avatar widget implemented as a state machine", | ||
@@ -31,8 +31,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/anatomy": "0.0.0-dev-20230713105642", | ||
"@zag-js/mutation-observer": "0.0.0-dev-20230713105642", | ||
"@zag-js/core": "0.0.0-dev-20230713105642", | ||
"@zag-js/dom-query": "0.0.0-dev-20230713105642", | ||
"@zag-js/utils": "0.0.0-dev-20230713105642", | ||
"@zag-js/types": "0.0.0-dev-20230713105642" | ||
"@zag-js/anatomy": "0.0.0-dev-20230713124852", | ||
"@zag-js/mutation-observer": "0.0.0-dev-20230713124852", | ||
"@zag-js/core": "0.0.0-dev-20230713124852", | ||
"@zag-js/dom-query": "0.0.0-dev-20230713124852", | ||
"@zag-js/utils": "0.0.0-dev-20230713124852", | ||
"@zag-js/types": "0.0.0-dev-20230713124852" | ||
}, | ||
@@ -39,0 +39,0 @@ "devDependencies": { |
@@ -5,5 +5,5 @@ import { dataAttr } from "@zag-js/dom-query" | ||
import { dom } from "./avatar.dom" | ||
import type { Send, State } from "./avatar.types" | ||
import type { PublicApi, Send, State } from "./avatar.types" | ||
export function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>) { | ||
export function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): PublicApi<T> { | ||
const isLoaded = state.matches("loaded") | ||
@@ -13,25 +13,12 @@ const showFallback = !isLoaded | ||
return { | ||
/** | ||
* Whether the image is loaded. | ||
*/ | ||
isLoaded, | ||
/** | ||
* Whether the fallback is shown. | ||
*/ | ||
showFallback, | ||
/** | ||
* Function to set new src. | ||
*/ | ||
setSrc(src: string) { | ||
send({ type: "SRC.SET", src }) | ||
}, | ||
/** | ||
* Function to set loaded state. | ||
*/ | ||
setLoaded() { | ||
send({ type: "IMG.LOADED", src: "api" }) | ||
}, | ||
/** | ||
* Function to set error state. | ||
*/ | ||
setError() { | ||
@@ -38,0 +25,0 @@ send({ type: "IMG.ERROR", src: "api" }) |
import type { StateMachine as S } from "@zag-js/core" | ||
import type { CommonProperties, Context, RequiredBy } from "@zag-js/types" | ||
import type { CommonProperties, Context, PropTypes, RequiredBy } from "@zag-js/types" | ||
@@ -9,2 +9,28 @@ type PublicContext = CommonProperties & { | ||
export type PublicApi<T extends PropTypes = PropTypes> = { | ||
/** | ||
* Whether the image is loaded. | ||
*/ | ||
isLoaded: boolean | ||
/** | ||
* Whether the fallback is shown. | ||
*/ | ||
showFallback: boolean | ||
/** | ||
* Function to set new src. | ||
*/ | ||
setSrc(src: string): void | ||
/** | ||
* Function to set loaded state. | ||
*/ | ||
setLoaded(): void | ||
/** | ||
* Function to set error state. | ||
*/ | ||
setError(): void | ||
rootProps: T["element"] | ||
imageProps: T["img"] | ||
fallbackProps: T["element"] | ||
} | ||
type PrivateContext = Context<{}> | ||
@@ -11,0 +37,0 @@ |
export { anatomy } from "./avatar.anatomy" | ||
export { connect } from "./avatar.connect" | ||
export { machine } from "./avatar.machine" | ||
export type { UserDefinedContext as Context } from "./avatar.types" | ||
export type { UserDefinedContext as Context, PublicApi } from "./avatar.types" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39540
597
+ Added@zag-js/anatomy@0.0.0-dev-20230713124852(transitive)
+ Added@zag-js/core@0.0.0-dev-20230713124852(transitive)
+ Added@zag-js/dom-query@0.0.0-dev-20230713124852(transitive)
+ Added@zag-js/mutation-observer@0.0.0-dev-20230713124852(transitive)
+ Added@zag-js/store@0.0.0-dev-20230713124852(transitive)
+ Added@zag-js/types@0.0.0-dev-20230713124852(transitive)
+ Added@zag-js/utils@0.0.0-dev-20230713124852(transitive)
- Removed@zag-js/anatomy@0.0.0-dev-20230713105642(transitive)
- Removed@zag-js/core@0.0.0-dev-20230713105642(transitive)
- Removed@zag-js/dom-query@0.0.0-dev-20230713105642(transitive)
- Removed@zag-js/mutation-observer@0.0.0-dev-20230713105642(transitive)
- Removed@zag-js/store@0.0.0-dev-20230713105642(transitive)
- Removed@zag-js/types@0.0.0-dev-20230713105642(transitive)
- Removed@zag-js/utils@0.0.0-dev-20230713105642(transitive)