@tamagui/label 1.0.1-beta.192 → 1.0.1-beta.194
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/cjs/Label.js +4 -2
- package/dist/cjs/Label.js.map +2 -2
- package/dist/esm/Label.js +5 -10
- package/dist/esm/Label.js.map +2 -2
- package/dist/jsx/Label.js +5 -10
- package/dist/jsx/Label.js.map +2 -2
- package/package.json +9 -7
- package/src/Label.tsx +6 -13
- package/types/Label.d.ts +3 -3
package/dist/cjs/Label.js
CHANGED
|
@@ -34,6 +34,8 @@ var import_compose_refs = require("@tamagui/compose-refs");
|
|
|
34
34
|
var import_core = require("@tamagui/core");
|
|
35
35
|
var import_create_context = require("@tamagui/create-context");
|
|
36
36
|
var import_focusable = require("@tamagui/focusable");
|
|
37
|
+
var import_get_button_sized = require("@tamagui/get-button-sized");
|
|
38
|
+
var import_get_font_sized = require("@tamagui/get-font-sized");
|
|
37
39
|
var import_text = require("@tamagui/text");
|
|
38
40
|
var React = __toESM(require("react"));
|
|
39
41
|
const NAME = "Label";
|
|
@@ -56,9 +58,9 @@ const LabelFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
|
56
58
|
variants: {
|
|
57
59
|
size: {
|
|
58
60
|
"...size": (val, extras) => {
|
|
59
|
-
const buttonStyle = (0,
|
|
61
|
+
const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras);
|
|
60
62
|
return {
|
|
61
|
-
...(0,
|
|
63
|
+
...(0, import_get_font_sized.getFontSized)(val, extras),
|
|
62
64
|
height: buttonStyle.height,
|
|
63
65
|
lineHeight: buttonStyle.height
|
|
64
66
|
};
|
package/dist/cjs/Label.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { GetProps, ReactComponentWithRef, isWeb, styled, themeable, useId } from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$4',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n selectable: false,\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(event.target as any as Node)\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n})\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAA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EtB,MAAM,QACX,WAAW,gBAAY,uBAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
|
|
6
6
|
"names": ["ariaLabelledBy"]
|
|
7
7
|
}
|
package/dist/esm/Label.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
|
-
import {
|
|
4
|
-
getButtonSize,
|
|
5
|
-
getFont,
|
|
6
|
-
isWeb,
|
|
7
|
-
styled,
|
|
8
|
-
themeable,
|
|
9
|
-
useId
|
|
10
|
-
} from "@tamagui/core";
|
|
3
|
+
import { isWeb, styled, themeable, useId } from "@tamagui/core";
|
|
11
4
|
import { createContext } from "@tamagui/create-context";
|
|
12
5
|
import { focusFocusable } from "@tamagui/focusable";
|
|
6
|
+
import { getButtonSized } from "@tamagui/get-button-sized";
|
|
7
|
+
import { getFontSized } from "@tamagui/get-font-sized";
|
|
13
8
|
import { SizableText } from "@tamagui/text";
|
|
14
9
|
import * as React from "react";
|
|
15
10
|
const NAME = "Label";
|
|
@@ -32,9 +27,9 @@ const LabelFrame = styled(SizableText, {
|
|
|
32
27
|
variants: {
|
|
33
28
|
size: {
|
|
34
29
|
"...size": (val, extras) => {
|
|
35
|
-
const buttonStyle =
|
|
30
|
+
const buttonStyle = getButtonSized(val, extras);
|
|
36
31
|
return {
|
|
37
|
-
...
|
|
32
|
+
...getFontSized(val, extras),
|
|
38
33
|
height: buttonStyle.height,
|
|
39
34
|
lineHeight: buttonStyle.height
|
|
40
35
|
};
|
package/dist/esm/Label.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { GetProps, ReactComponentWithRef, isWeb, styled, themeable, useId } from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$4',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n selectable: false,\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(event.target as any as Node)\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n})\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element)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BAAe,MAAM,OAAO;AAAA,UAC9B;AAAA,QACF;AAAA,MACF;AAAA,KACF;AAAA,GACF;AAEJ,CAAC;AAED,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
|
|
6
6
|
"names": ["ariaLabelledBy"]
|
|
7
7
|
}
|
package/dist/jsx/Label.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
-
import {
|
|
3
|
-
getButtonSize,
|
|
4
|
-
getFont,
|
|
5
|
-
isWeb,
|
|
6
|
-
styled,
|
|
7
|
-
themeable,
|
|
8
|
-
useId
|
|
9
|
-
} from "@tamagui/core";
|
|
2
|
+
import { isWeb, styled, themeable, useId } from "@tamagui/core";
|
|
10
3
|
import { createContext } from "@tamagui/create-context";
|
|
11
4
|
import { focusFocusable } from "@tamagui/focusable";
|
|
5
|
+
import { getButtonSized } from "@tamagui/get-button-sized";
|
|
6
|
+
import { getFontSized } from "@tamagui/get-font-sized";
|
|
12
7
|
import { SizableText } from "@tamagui/text";
|
|
13
8
|
import * as React from "react";
|
|
14
9
|
const NAME = "Label";
|
|
@@ -31,9 +26,9 @@ const LabelFrame = styled(SizableText, {
|
|
|
31
26
|
variants: {
|
|
32
27
|
size: {
|
|
33
28
|
"...size": (val, extras) => {
|
|
34
|
-
const buttonStyle =
|
|
29
|
+
const buttonStyle = getButtonSized(val, extras);
|
|
35
30
|
return {
|
|
36
|
-
...
|
|
31
|
+
...getFontSized(val, extras),
|
|
37
32
|
height: buttonStyle.height,
|
|
38
33
|
lineHeight: buttonStyle.height
|
|
39
34
|
};
|
package/dist/jsx/Label.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAAuB;AAChC
|
|
4
|
+
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { GetProps, ReactComponentWithRef, isWeb, styled, themeable, useId } from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n size: '$4',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n selectable: false,\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor)\n const label = ref.current\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby')\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n controlRef.current = element\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n if (!id) return\n const ariaLabelledBy = getAriaLabel()?.replace(id, '')\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby')\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy)\n }\n }\n }\n }\n }, [id, htmlFor])\n }\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n // @ts-ignore\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(event.target as any as Node)\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click()\n controlRef.current.focus()\n }\n } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n})\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer')\n const { controlRef } = context\n\n React.useEffect(() => {\n if (element) controlRef.current = element\n }, [element, controlRef])\n\n return context.id\n}\n\nconst Root = Label\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAChC,SAA0C,OAAO,QAAQ,WAAW,aAAa;AACjF,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,YAAY,WAAW;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,mBAAmB,IAAI,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,cAAc,eAAe,KAAK,MAAM;AAC9C,eAAO;AAAA,UACL,GAAG,aAAa,KAAK,MAAM;AAAA,UAC3B,QAAQ,YAAY;AAAA,UACpB,YAAY,YAAY;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAMD,MAAM,iBAAiB,MAAM,WAA0C,CAAC,OAAO,iBAAiB;AAC9F,QAAM,EAAE,SAAS,IAAI,WAAW,WAAW,IAAI;AAC/C,QAAM,aAAa,MAAM,OAA2B,IAAI;AACxD,QAAM,MAAM,MAAM,OAAY,IAAI;AAClC,QAAM,eAAe,gBAAgB,cAAc,GAAG;AACtD,QAAM,WAAW,MAAM;AACvB,QAAM,K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Ae,MAAM,OAAO;AAAA,MAC9B;AAAA,IACF;AAAA,EACF,GACF,EACF,EAvCC;AAyCL,CAAC;AAED,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,UAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,WAAW,IAAI;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
|
|
6
6
|
"names": ["ariaLabelledBy"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/label",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.194",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -23,11 +23,13 @@
|
|
|
23
23
|
"clean:build": "tamagui-build clean:build"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
28
|
-
"@tamagui/create-context": "^1.0.1-beta.
|
|
29
|
-
"@tamagui/focusable": "^1.0.1-beta.
|
|
30
|
-
"@tamagui/
|
|
26
|
+
"@tamagui/compose-refs": "^1.0.1-beta.194",
|
|
27
|
+
"@tamagui/core": "^1.0.1-beta.194",
|
|
28
|
+
"@tamagui/create-context": "^1.0.1-beta.194",
|
|
29
|
+
"@tamagui/focusable": "^1.0.1-beta.194",
|
|
30
|
+
"@tamagui/get-button-sized": "^1.0.1-beta.194",
|
|
31
|
+
"@tamagui/get-font-sized": "^1.0.1-beta.194",
|
|
32
|
+
"@tamagui/text": "^1.0.1-beta.194"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
|
33
35
|
"react": "*",
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
"react-native": "*"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
40
|
+
"@tamagui/build": "^1.0.1-beta.194",
|
|
39
41
|
"@types/react-native": "^0.69.2",
|
|
40
42
|
"react": "*",
|
|
41
43
|
"react-dom": "*",
|
package/src/Label.tsx
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
2
|
-
import {
|
|
3
|
-
GetProps,
|
|
4
|
-
ReactComponentWithRef,
|
|
5
|
-
getButtonSize,
|
|
6
|
-
getFont,
|
|
7
|
-
isWeb,
|
|
8
|
-
styled,
|
|
9
|
-
themeable,
|
|
10
|
-
useId,
|
|
11
|
-
} from '@tamagui/core'
|
|
2
|
+
import { GetProps, ReactComponentWithRef, isWeb, styled, themeable, useId } from '@tamagui/core'
|
|
12
3
|
import { createContext } from '@tamagui/create-context'
|
|
13
4
|
import { focusFocusable } from '@tamagui/focusable'
|
|
5
|
+
import { getButtonSized } from '@tamagui/get-button-sized'
|
|
6
|
+
import { getFontSized } from '@tamagui/get-font-sized'
|
|
14
7
|
import { SizableText } from '@tamagui/text'
|
|
15
8
|
import * as React from 'react'
|
|
16
9
|
import { View } from 'react-native'
|
|
@@ -42,9 +35,9 @@ export const LabelFrame = styled(SizableText, {
|
|
|
42
35
|
variants: {
|
|
43
36
|
size: {
|
|
44
37
|
'...size': (val, extras) => {
|
|
45
|
-
const buttonStyle =
|
|
38
|
+
const buttonStyle = getButtonSized(val, extras)
|
|
46
39
|
return {
|
|
47
|
-
...
|
|
40
|
+
...getFontSized(val, extras),
|
|
48
41
|
height: buttonStyle.height,
|
|
49
42
|
lineHeight: buttonStyle.height,
|
|
50
43
|
}
|
|
@@ -100,7 +93,7 @@ const LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((props, f
|
|
|
100
93
|
role="label"
|
|
101
94
|
id={id}
|
|
102
95
|
{...labelProps}
|
|
103
|
-
ref={composedRefs}
|
|
96
|
+
ref={composedRefs as any}
|
|
104
97
|
onMouseDown={(event) => {
|
|
105
98
|
props.onMouseDown?.(event)
|
|
106
99
|
// prevent text selection when double clicking label
|
package/types/Label.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { GetProps, ReactComponentWithRef } from '@tamagui/core';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
|
-
export declare const LabelFrame: import("@tamagui/core").TamaguiComponent<Omit<import("react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
3
|
+
export declare const LabelFrame: import("@tamagui/core").TamaguiComponent<Omit<import("@tamagui/types-react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
4
4
|
readonly size?: import("@tamagui/core").FontSizeTokens | undefined;
|
|
5
5
|
}, "size"> & {
|
|
6
6
|
readonly size?: import("@tamagui/core").SizeTokens | undefined;
|
|
7
|
-
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
7
|
+
} & import("@tamagui/core").MediaProps<Partial<Omit<import("@tamagui/types-react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
8
8
|
readonly size?: import("@tamagui/core").FontSizeTokens | undefined;
|
|
9
9
|
}, "size"> & {
|
|
10
10
|
readonly size?: import("@tamagui/core").SizeTokens | undefined;
|
|
11
|
-
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
11
|
+
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("@tamagui/types-react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
12
12
|
readonly size?: import("@tamagui/core").FontSizeTokens | undefined;
|
|
13
13
|
}, "size"> & {
|
|
14
14
|
readonly size?: import("@tamagui/core").SizeTokens | undefined;
|