Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
feat: Add Time Component (#3369)
Ivan Starkov0b48e9d314fa
diff --git a/packages/icons/icons/calendar.svg b/packages/icons/icons/calendar.svgnew file mode 100644index 0000000000..5180dca8e2--- /dev/null+++ b/packages/icons/icons/calendar.svg@@ -0,0 +1,5 @@+<svg width="14" height="16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path+ d="M4.203.702a.713.713 0 0 0-.366.213c-.124.148-.137.208-.15.672l-.012.431-.443.015c-.481.017-.686.041-.991.117-.651.161-1.273.668-1.586 1.29a2.834 2.834 0 0 0-.252.839c-.038.241-.041.553-.041 4.366 0 4.4-.002 4.323.117 4.784.107.412.325.79.639 1.106.422.426.865.64 1.536.742.255.038.554.041 4.346.041s4.091-.003 4.346-.041c.671-.102 1.114-.316 1.536-.742.314-.316.532-.694.639-1.106.119-.461.117-.384.117-4.784 0-3.813-.003-4.125-.041-4.366a2.834 2.834 0 0 0-.252-.839c-.313-.622-.935-1.129-1.586-1.29-.305-.076-.51-.1-.991-.117l-.443-.015-.012-.431c-.013-.488-.039-.581-.204-.726C9.91.687 9.61.64 9.39.75c-.132.066-.302.249-.339.366a3.432 3.432 0 0 0-.038.5l-.011.414H4.998l-.011-.414a3.432 3.432 0 0 0-.038-.5c-.036-.115-.207-.3-.332-.361a.689.689 0 0 0-.414-.053m-.516 3.026c0 .386.004.422.055.532a.734.734 0 0 0 .314.328.777.777 0 0 0 .523.014.699.699 0 0 0 .346-.338c.048-.109.055-.167.064-.536l.01-.415h4.002l.01.415c.009.369.016.427.064.536a.699.699 0 0 0 .346.338c.129.057.391.05.523-.014a.734.734 0 0 0 .314-.328c.051-.11.055-.146.055-.53v-.412l.333.01c.407.013.692.045.846.095.333.107.672.458.765.792.059.212.086.598.086 1.227v.578H1.657v-.578c0-.629.027-1.015.086-1.227.093-.335.434-.688.765-.791.182-.057.277-.07.665-.087l.438-.02.076-.004v.415m8.656 6.183c-.001 2.471-.01 2.897-.072 3.167-.065.288-.345.632-.63.777-.324.165-.086.157-4.641.157s-4.317.008-4.641-.157c-.285-.145-.565-.489-.63-.777-.062-.27-.071-.696-.072-3.167V7.327h10.686v2.584m-5.547-1.86c-.098.03-1.16.736-1.264.841-.233.233-.236.626-.008.886a.666.666 0 0 0 .7.167l.123-.047v1.459l-.195.011c-.211.011-.337.064-.463.197-.231.244-.215.685.033.909.194.175.168.172 1.278.172s1.084.003 1.278-.172c.248-.224.264-.665.033-.909-.126-.133-.252-.186-.463-.197l-.195-.011V9.976c0-1.555.002-1.534-.166-1.725a.562.562 0 0 0-.452-.216.98.98 0 0 0-.239.016"+ fill-rule="evenodd" fill="currentColor" />+</svg>\ No newline at end of filediff --git a/packages/icons/src/__generated__/calendar.tsx b/packages/icons/src/__generated__/calendar.tsxnew file mode 100644index 0000000000..5631ca6266--- /dev/null+++ b/packages/icons/src/__generated__/calendar.tsx@@ -0,0 +1,15 @@+// Generated from icons/calendar.svg++import { forwardRef } from "react";+import type { IconProps } from "../types";++// prettier-ignore+export const CalendarIcon = forwardRef<SVGSVGElement, IconProps>(+ ({ color = "currentColor", size = 16, ...props }, forwardedRef) => {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 16" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path fill="currentColor" fillRule="evenodd" d="M4.203.702a.713.713 0 0 0-.366.213c-.124.148-.137.208-.15.672l-.012.431-.443.015c-.481.017-.686.041-.991.117-.651.161-1.273.668-1.586 1.29a2.834 2.834 0 0 0-.252.839c-.038.241-.041.553-.041 4.366 0 4.4-.002 4.323.117 4.784.107.412.325.79.639 1.106.422.426.865.64 1.536.742.255.038.554.041 4.346.041s4.091-.003 4.346-.041c.671-.102 1.114-.316 1.536-.742.314-.316.532-.694.639-1.106.119-.461.117-.384.117-4.784 0-3.813-.003-4.125-.041-4.366a2.834 2.834 0 0 0-.252-.839c-.313-.622-.935-1.129-1.586-1.29-.305-.076-.51-.1-.991-.117l-.443-.015-.012-.431c-.013-.488-.039-.581-.204-.726C9.91.687 9.61.64 9.39.75c-.132.066-.302.249-.339.366a3.432 3.432 0 0 0-.038.5l-.011.414H4.998l-.011-.414a3.432 3.432 0 0 0-.038-.5c-.036-.115-.207-.3-.332-.361a.689.689 0 0 0-.414-.053m-.516 3.026c0 .386.004.422.055.532a.734.734 0 0 0 .314.328.777.777 0 0 0 .523.014.699.699 0 0 0 .346-.338c.048-.109.055-.167.064-.536l.01-.415h4.002l.01.415c.009.369.016.427.064.536a.699.699 0 0 0 .346.338c.129.057.391.05.523-.014a.734.734 0 0 0 .314-.328c.051-.11.055-.146.055-.53v-.412l.333.01c.407.013.692.045.846.095.333.107.672.458.765.792.059.212.086.598.086 1.227v.578H1.657v-.578c0-.629.027-1.015.086-1.227.093-.335.434-.688.765-.791.182-.057.277-.07.665-.087l.438-.02.076-.004v.415m8.656 6.183c-.001 2.471-.01 2.897-.072 3.167-.065.288-.345.632-.63.777-.324.165-.086.157-4.641.157s-4.317.008-4.641-.157c-.285-.145-.565-.489-.63-.777-.062-.27-.071-.696-.072-3.167V7.327h10.686v2.584m-5.547-1.86c-.098.03-1.16.736-1.264.841-.233.233-.236.626-.008.886a.666.666 0 0 0 .7.167l.123-.047v1.459l-.195.011c-.211.011-.337.064-.463.197-.231.244-.215.685.033.909.194.175.168.172 1.278.172s1.084.003 1.278-.172c.248-.224.264-.665.033-.909-.126-.133-.252-.186-.463-.197l-.195-.011V9.976c0-1.555.002-1.534-.166-1.725a.562.562 0 0 0-.452-.216.98.98 0 0 0-.239.016" /></svg>+ );+ }+);++CalendarIcon.displayName = "CalendarIcon";diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.tsindex 2492816c60..736573debf 100644--- a/packages/icons/src/__generated__/index.ts+++ b/packages/icons/src/__generated__/index.ts@@ -47,6 +47,7 @@ export * from "./bp-star-off";export * from "./bp-star-on";export * from "./bug";export * from "./button-element";+export * from "./calendar";export * from "./check-circle";export * from "./check-mark";export * from "./checkbox-checked-filled";diff --git a/packages/icons/src/__generated__/svg/calendar.ts b/packages/icons/src/__generated__/svg/calendar.tsnew file mode 100644index 0000000000..ce5a31937d--- /dev/null+++ b/packages/icons/src/__generated__/svg/calendar.ts@@ -0,0 +1 @@+export const CalendarIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 16" width="100%" height="100%" style="display: block;"><path fill="currentColor" fill-rule="evenodd" d="M4.203.702a.713.713 0 0 0-.366.213c-.124.148-.137.208-.15.672l-.012.431-.443.015c-.481.017-.686.041-.991.117-.651.161-1.273.668-1.586 1.29a2.834 2.834 0 0 0-.252.839c-.038.241-.041.553-.041 4.366 0 4.4-.002 4.323.117 4.784.107.412.325.79.639 1.106.422.426.865.64 1.536.742.255.038.554.041 4.346.041s4.091-.003 4.346-.041c.671-.102 1.114-.316 1.536-.742.314-.316.532-.694.639-1.106.119-.461.117-.384.117-4.784 0-3.813-.003-4.125-.041-4.366a2.834 2.834 0 0 0-.252-.839c-.313-.622-.935-1.129-1.586-1.29-.305-.076-.51-.1-.991-.117l-.443-.015-.012-.431c-.013-.488-.039-.581-.204-.726C9.91.687 9.61.64 9.39.75c-.132.066-.302.249-.339.366a3.432 3.432 0 0 0-.038.5l-.011.414H4.998l-.011-.414a3.432 3.432 0 0 0-.038-.5c-.036-.115-.207-.3-.332-.361a.689.689 0 0 0-.414-.053m-.516 3.026c0 .386.004.422.055.532a.734.734 0 0 0 .314.328.777.777 0 0 0 .523.014.699.699 0 0 0 .346-.338c.048-.109.055-.167.064-.536l.01-.415h4.002l.01.415c.009.369.016.427.064.536a.699.699 0 0 0 .346.338c.129.057.391.05.523-.014a.734.734 0 0 0 .314-.328c.051-.11.055-.146.055-.53v-.412l.333.01c.407.013.692.045.846.095.333.107.672.458.765.792.059.212.086.598.086 1.227v.578H1.657v-.578c0-.629.027-1.015.086-1.227.093-.335.434-.688.765-.791.182-.057.277-.07.665-.087l.438-.02.076-.004v.415m8.656 6.183c-.001 2.471-.01 2.897-.072 3.167-.065.288-.345.632-.63.777-.324.165-.086.157-4.641.157s-4.317.008-4.641-.157c-.285-.145-.565-.489-.63-.777-.062-.27-.071-.696-.072-3.167V7.327h10.686v2.584m-5.547-1.86c-.098.03-1.16.736-1.264.841-.233.233-.236.626-.008.886a.666.666 0 0 0 .7.167l.123-.047v1.459l-.195.011c-.211.011-.337.064-.463.197-.231.244-.215.685.033.909.194.175.168.172 1.278.172s1.084.003 1.278-.172c.248-.224.264-.665.033-.909-.126-.133-.252-.186-.463-.197l-.195-.011V9.976c0-1.555.002-1.534-.166-1.725a.562.562 0 0 0-.452-.216.98.98 0 0 0-.239.016"/></svg>`;diff --git a/packages/icons/src/__generated__/svg/index.ts b/packages/icons/src/__generated__/svg/index.tsindex 1e33db4d0b..c1248c2326 100644--- a/packages/icons/src/__generated__/svg/index.ts+++ b/packages/icons/src/__generated__/svg/index.ts@@ -47,6 +47,7 @@ export { BpStarOffIcon } from "./bp-star-off";export { BpStarOnIcon } from "./bp-star-on";export { BugIcon } from "./bug";export { ButtonElementIcon } from "./button-element";+export { CalendarIcon } from "./calendar";export { CheckCircleIcon } from "./check-circle";export { CheckMarkIcon } from "./check-mark";export { CheckboxCheckedFilledIcon } from "./checkbox-checked-filled";diff --git a/packages/react-sdk/src/css/normalize.ts b/packages/react-sdk/src/css/normalize.tsindex 78f24d1cc9..38ef72452c 100644--- a/packages/react-sdk/src/css/normalize.ts+++ b/packages/react-sdk/src/css/normalize.ts@@ -51,6 +51,7 @@ export const nav = baseStyle;export const section = baseStyle;export const form = baseStyle;export const label = baseStyle;+export const time = baseStyle;export const h1 = baseStyle;export const h2 = baseStyle;diff --git a/packages/sdk-components-react/src/__generated__/local-date.props.ts b/packages/sdk-components-react/src/__generated__/local-date.props.tsnew file mode 100644index 0000000000..64f8587a88--- /dev/null+++ b/packages/sdk-components-react/src/__generated__/local-date.props.ts@@ -0,0 +1,301 @@+import type { PropMeta } from "@webstudio-is/react-sdk";++export const props: Record<string, PropMeta> = {+ country: {+ required: true,+ control: "select",+ type: "string",+ options: [+ "AF",+ "AL",+ "DZ",+ "AS",+ "AD",+ "AO",+ "AI",+ "AQ",+ "AG",+ "AR",+ "AM",+ "AW",+ "AU",+ "AT",+ "AZ",+ "BS",+ "BH",+ "BD",+ "BB",+ "BY",+ "BE",+ "BZ",+ "BJ",+ "BM",+ "BT",+ "BO",+ "BA",+ "BW",+ "BR",+ "BN",+ "BG",+ "BF",+ "BI",+ "CV",+ "KH",+ "CM",+ "CA",+ "KY",+ "CF",+ "TD",+ "CL",+ "CN",+ "CO",+ "KM",+ "CG",+ "CD",+ "CR",+ "HR",+ "CU",+ "CY",+ "CZ",+ "DK",+ "DJ",+ "DM",+ "DO",+ "EC",+ "EG",+ "SV",+ "GQ",+ "ER",+ "EE",+ "SZ",+ "ET",+ "FJ",+ "FI",+ "FR",+ "GA",+ "GM",+ "GE",+ "DE",+ "GH",+ "GR",+ "GD",+ "GT",+ "GN",+ "GW",+ "GY",+ "HT",+ "HN",+ "HU",+ "IS",+ "IN",+ "ID",+ "IR",+ "IQ",+ "IE",+ "IL",+ "IT",+ "JM",+ "JP",+ "JO",+ "KZ",+ "KE",+ "KI",+ "KP",+ "KR",+ "KW",+ "KG",+ "LA",+ "LV",+ "LB",+ "LS",+ "LR",+ "LY",+ "LI",+ "LT",+ "LU",+ "MG",+ "MW",+ "MY",+ "MV",+ "ML",+ "MT",+ "MH",+ "MR",+ "MU",+ "MX",+ "FM",+ "MD",+ "MC",+ "MN",+ "ME",+ "MA",+ "MZ",+ "MM",+ "NA",+ "NR",+ "NP",+ "NL",+ "NZ",+ "NI",+ "NE",+ "NG",+ "NO",+ "OM",+ "PK",+ "PW",+ "PA",+ "PG",+ "PY",+ "PE",+ "PH",+ "PL",+ "PT",+ "QA",+ "RO",+ "RU",+ "RW",+ "KN",+ "LC",+ "VC",+ "WS",+ "SM",+ "ST",+ "SA",+ "SN",+ "RS",+ "SC",+ "SL",+ "SG",+ "SK",+ "SI",+ "SB",+ "SO",+ "ZA",+ "SS",+ "ES",+ "LK",+ "SD",+ "SR",+ "SE",+ "CH",+ "SY",+ "TW",+ "TJ",+ "TZ",+ "TH",+ "TL",+ "TG",+ "TO",+ "TT",+ "TN",+ "TR",+ "TM",+ "TV",+ "UG",+ "UA",+ "AE",+ "GB",+ "US",+ "UY",+ "UZ",+ "VU",+ "VA",+ "VE",+ "VN",+ "YE",+ "ZM",+ "ZW",+ ],+ },+ dateStyle: {+ required: true,+ control: "select",+ type: "string",+ options: ["full", "long", "medium", "short", "none"],+ },+ language: {+ required: true,+ control: "select",+ type: "string",+ options: [+ "af",+ "am",+ "ar",+ "az",+ "be",+ "bg",+ "bn",+ "bs",+ "ca",+ "cs",+ "cy",+ "da",+ "de",+ "el",+ "en",+ "es",+ "et",+ "eu",+ "fa",+ "fi",+ "fr",+ "ga",+ "gl",+ "gu",+ "he",+ "hi",+ "hr",+ "hu",+ "hy",+ "id",+ "is",+ "it",+ "ja",+ "ka",+ "kk",+ "km",+ "kn",+ "ko",+ "ky",+ "lb",+ "lt",+ "lv",+ "mk",+ "ml",+ "mn",+ "mr",+ "ms",+ "mt",+ "nb",+ "nl",+ "nn",+ "pl",+ "pt",+ "ro",+ "ru",+ "si",+ "sk",+ "sl",+ "sq",+ "sr",+ "sv",+ "sw",+ "ta",+ "te",+ "th",+ "tr",+ "uk",+ "ur",+ "uz",+ "vi",+ "zh",+ ],+ description: "Defines the script language used in the element.",+ },+ timeStyle: {+ required: true,+ control: "select",+ type: "string",+ options: ["full", "long", "medium", "short", "none"],+ },+};diff --git a/packages/sdk-components-react/src/__generated__/time.props.ts b/packages/sdk-components-react/src/__generated__/time.props.tsnew file mode 100644index 0000000000..9f507ebc67--- /dev/null+++ b/packages/sdk-components-react/src/__generated__/time.props.ts@@ -0,0 +1,311 @@+import type { PropMeta } from "@webstudio-is/react-sdk";++export const props: Record<string, PropMeta> = {+ country: {+ required: false,+ control: "select",+ type: "string",+ defaultValue: "GB",+ options: [+ "AF",+ "AL",+ "DZ",+ "AS",+ "AD",+ "AO",+ "AI",+ "AQ",+ "AG",+ "AR",+ "AM",+ "AW",+ "AU",+ "AT",+ "AZ",+ "BS",+ "BH",+ "BD",+ "BB",+ "BY",+ "BE",+ "BZ",+ "BJ",+ "BM",+ "BT",+ "BO",+ "BA",+ "BW",+ "BR",+ "BN",+ "BG",+ "BF",+ "BI",+ "CV",+ "KH",+ "CM",+ "CA",+ "KY",+ "CF",+ "TD",+ "CL",+ "CN",+ "CO",+ "KM",+ "CG",+ "CD",+ "CR",+ "HR",+ "CU",+ "CY",+ "CZ",+ "DK",+ "DJ",+ "DM",+ "DO",+ "EC",+ "EG",+ "SV",+ "GQ",+ "ER",+ "EE",+ "SZ",+ "ET",+ "FJ",+ "FI",+ "FR",+ "GA",+ "GM",+ "GE",+ "DE",+ "GH",+ "GR",+ "GD",+ "GT",+ "GN",+ "GW",+ "GY",+ "HT",+ "HN",+ "HU",+ "IS",+ "IN",+ "ID",+ "IR",+ "IQ",+ "IE",+ "IL",+ "IT",+ "JM",+ "JP",+ "JO",+ "KZ",+ "KE",+ "KI",+ "KP",+ "KR",+ "KW",+ "KG",+ "LA",+ "LV",+ "LB",+ "LS",+ "LR",+ "LY",+ "LI",+ "LT",+ "LU",+ "MG",+ "MW",+ "MY",+ "MV",+ "ML",+ "MT",+ "MH",+ "MR",+ "MU",+ "MX",+ "FM",+ "MD",+ "MC",+ "MN",+ "ME",+ "MA",+ "MZ",+ "MM",+ "NA",+ "NR",+ "NP",+ "NL",+ "NZ",+ "NI",+ "NE",+ "NG",+ "NO",+ "OM",+ "PK",+ "PW",+ "PA",+ "PG",+ "PY",+ "PE",+ "PH",+ "PL",+ "PT",+ "QA",+ "RO",+ "RU",+ "RW",+ "KN",+ "LC",+ "VC",+ "WS",+ "SM",+ "ST",+ "SA",+ "SN",+ "RS",+ "SC",+ "SL",+ "SG",+ "SK",+ "SI",+ "SB",+ "SO",+ "ZA",+ "SS",+ "ES",+ "LK",+ "SD",+ "SR",+ "SE",+ "CH",+ "SY",+ "TW",+ "TJ",+ "TZ",+ "TH",+ "TL",+ "TG",+ "TO",+ "TT",+ "TN",+ "TR",+ "TM",+ "TV",+ "UG",+ "UA",+ "AE",+ "GB",+ "US",+ "UY",+ "UZ",+ "VU",+ "VA",+ "VE",+ "VN",+ "YE",+ "ZM",+ "ZW",+ ],+ },+ dateStyle: {+ required: false,+ control: "select",+ type: "string",+ defaultValue: "medium",+ options: ["full", "long", "medium", "short", "none"],+ },+ datetime: {+ required: false,+ control: "text",+ type: "string",+ defaultValue: "dateTime attribute is not set",+ },+ language: {+ required: false,+ control: "select",+ type: "string",+ defaultValue: "en",+ options: [+ "hr",+ "th",+ "tr",+ "id",+ "is",+ "cy",+ "fr",+ "af",+ "am",+ "ar",+ "az",+ "be",+ "bg",+ "bn",+ "bs",+ "ca",+ "cs",+ "da",+ "de",+ "el",+ "en",+ "es",+ "et",+ "eu",+ "fa",+ "fi",+ "ga",+ "gl",+ "gu",+ "he",+ "hi",+ "hu",+ "hy",+ "it",+ "ja",+ "ka",+ "kk",+ "km",+ "kn",+ "ko",+ "ky",+ "lb",+ "lt",+ "lv",+ "mk",+ "ml",+ "mn",+ "mr",+ "ms",+ "mt",+ "nb",+ "nl",+ "nn",+ "pl",+ "pt",+ "ro",+ "ru",+ "si",+ "sk",+ "sl",+ "sq",+ "sr",+ "sv",+ "sw",+ "ta",+ "te",+ "uk",+ "ur",+ "uz",+ "vi",+ "zh",+ ],+ description: "Defines the script language used in the element.",+ },+ timeStyle: {+ required: false,+ control: "select",+ type: "string",+ defaultValue: "none",+ options: ["full", "long", "medium", "short", "none"],+ },+};diff --git a/packages/sdk-components-react/src/__generated__/xml-node.props.ts b/packages/sdk-components-react/src/__generated__/xml-node.props.tsindex ad701984c3..3e6f0218dd 100644--- a/packages/sdk-components-react/src/__generated__/xml-node.props.ts+++ b/packages/sdk-components-react/src/__generated__/xml-node.props.ts@@ -2,4 +2,5 @@ import type { PropMeta } from "@webstudio-is/react-sdk";export const props: Record<string, PropMeta> = {tag: { required: false, control: "text", type: "string", defaultValue: "" },+ xmlns: { required: false, control: "text", type: "string" },};diff --git a/packages/sdk-components-react/src/components.ts b/packages/sdk-components-react/src/components.tsindex 25cfea2ba9..fdb772c7a4 100644--- a/packages/sdk-components-react/src/components.ts+++ b/packages/sdk-components-react/src/components.ts@@ -31,3 +31,4 @@ export { VimeoPreviewImage } from "./vimeo-preview-image";export { VimeoPlayButton } from "./vimeo-play-button";export { VimeoSpinner } from "./vimeo-spinner";export { XmlNode } from "./xml-node";+export { Time } from "./time";diff --git a/packages/sdk-components-react/src/metas.ts b/packages/sdk-components-react/src/metas.tsindex 6f6982980d..6f81aec1d0 100644--- a/packages/sdk-components-react/src/metas.ts+++ b/packages/sdk-components-react/src/metas.ts@@ -32,3 +32,4 @@ export { meta as VimeoPreviewImage } from "./vimeo-preview-image.ws";export { meta as VimeoPlayButton } from "./vimeo-play-button.ws";export { meta as VimeoSpinner } from "./vimeo-spinner.ws";export { meta as XmlNode } from "./xml-node.ws";+export { meta as Time } from "./time.ws";diff --git a/packages/sdk-components-react/src/props.ts b/packages/sdk-components-react/src/props.tsindex 2413b43f5e..c40fcf9f79 100644--- a/packages/sdk-components-react/src/props.ts+++ b/packages/sdk-components-react/src/props.ts@@ -31,3 +31,4 @@ export { propsMeta as VimeoPreviewImage } from "./vimeo-preview-image.ws";export { propsMeta as VimeoPlayButton } from "./vimeo-play-button.ws";export { propsMeta as VimeoSpinner } from "./vimeo-spinner.ws";export { propsMeta as XmlNode } from "./xml-node.ws";+export { propsMeta as Time } from "./time.ws";diff --git a/packages/sdk-components-react/src/time.stories.tsx b/packages/sdk-components-react/src/time.stories.tsxnew file mode 100644index 0000000000..68762c00b5--- /dev/null+++ b/packages/sdk-components-react/src/time.stories.tsx@@ -0,0 +1,55 @@+import type { Meta, StoryObj } from "@storybook/react";++import { Time } from "./time";++const meta: Meta<typeof Time> = {+ title: "Components/Time",+ component: Time,+};++export default meta;++type Story = StoryObj<typeof Time>;++export const Default: Story = {+ args: {+ language: "en",+ country: "US",+ dateStyle: "full",+ timeStyle: "full",+ datetime: "2024-05-16T12:00:00Z",+ },+};++export const OptionsNotDefined: Story = {+ args: {+ datetime: "2024-05-16T12:00:00Z",+ },+};++export const NotDefined: Story = {+ args: {},+};++export const InvalidDateTime: Story = {+ args: {+ datetime: "Any Text Instead Of Date Time",+ },+};++export const InvalidOptionTypes: Story = {+ args: {+ language: {} as "en",+ country: {} as "US",+ dateStyle: {} as "full",+ timeStyle: {} as "full",++ datetime: "2024-05-16T12:00:00Z",+ },+};++export const InvalidDateTimeType: Story = {+ args: {+ datetime: {} as "2024-05-16T12:00:00Z",+ },+};diff --git a/packages/sdk-components-react/src/time.tsx b/packages/sdk-components-react/src/time.tsxnew file mode 100644index 0000000000..ad821c1a00--- /dev/null+++ b/packages/sdk-components-react/src/time.tsx@@ -0,0 +1,373 @@+import * as React from "react";++const languages = [+ "af",+ "am",+ "ar",+ "az",+ "be",+ "bg",+ "bn",+ "bs",+ "ca",+ "cs",+ "cy",+ "da",+ "de",+ "el",+ "en",+ "es",+ "et",+ "eu",+ "fa",+ "fi",+ "fr",+ "ga",+ "gl",+ "gu",+ "he",+ "hi",+ "hr",+ "hu",+ "hy",+ "id",+ "is",+ "it",+ "ja",+ "ka",+ "kk",+ "km",+ "kn",+ "ko",+ "ky",+ "lb",+ "lt",+ "lv",+ "mk",+ "ml",+ "mn",+ "mr",+ "ms",+ "mt",+ "nb",+ "nl",+ "nn",+ "pl",+ "pt",+ "ro",+ "ru",+ "si",+ "sk",+ "sl",+ "sq",+ "sr",+ "sv",+ "sw",+ "ta",+ "te",+ "th",+ "tr",+ "uk",+ "ur",+ "uz",+ "vi",+ "zh",+] as const;++const countries = [+ "AF",+ "AL",+ "DZ",+ "AS",+ "AD",+ "AO",+ "AI",+ "AQ",+ "AG",+ "AR",+ "AM",+ "AW",+ "AU",+ "AT",+ "AZ",+ "BS",+ "BH",+ "BD",+ "BB",+ "BY",+ "BE",+ "BZ",+ "BJ",+ "BM",+ "BT",+ "BO",+ "BA",+ "BW",+ "BR",+ "BN",+ "BG",+ "BF",+ "BI",+ "CV",+ "KH",+ "CM",+ "CA",+ "KY",+ "CF",+ "TD",+ "CL",+ "CN",+ "CO",+ "KM",+ "CG",+ "CD",+ "CR",+ "HR",+ "CU",+ "CY",+ "CZ",+ "DK",+ "DJ",+ "DM",+ "DO",+ "EC",+ "EG",+ "SV",+ "GQ",+ "ER",+ "EE",+ "SZ",+ "ET",+ "FJ",+ "FI",+ "FR",+ "GA",+ "GM",+ "GE",+ "DE",+ "GH",+ "GR",+ "GD",+ "GT",+ "GN",+ "GW",+ "GY",+ "HT",+ "HN",+ "HU",+ "IS",+ "IN",+ "ID",+ "IR",+ "IQ",+ "IE",+ "IL",+ "IT",+ "JM",+ "JP",+ "JO",+ "KZ",+ "KE",+ "KI",+ "KP",+ "KR",+ "KW",+ "KG",+ "LA",+ "LV",+ "LB",+ "LS",+ "LR",+ "LY",+ "LI",+ "LT",+ "LU",+ "MG",+ "MW",+ "MY",+ "MV",+ "ML",+ "MT",+ "MH",+ "MR",+ "MU",+ "MX",+ "FM",+ "MD",+ "MC",+ "MN",+ "ME",+ "MA",+ "MZ",+ "MM",+ "NA",+ "NR",+ "NP",+ "NL",+ "NZ",+ "NI",+ "NE",+ "NG",+ "NO",+ "OM",+ "PK",+ "PW",+ "PA",+ "PG",+ "PY",+ "PE",+ "PH",+ "PL",+ "PT",+ "QA",+ "RO",+ "RU",+ "RW",+ "KN",+ "LC",+ "VC",+ "WS",+ "SM",+ "ST",+ "SA",+ "SN",+ "RS",+ "SC",+ "SL",+ "SG",+ "SK",+ "SI",+ "SB",+ "SO",+ "ZA",+ "SS",+ "ES",+ "LK",+ "SD",+ "SR",+ "SE",+ "CH",+ "SY",+ "TW",+ "TJ",+ "TZ",+ "TH",+ "TL",+ "TG",+ "TO",+ "TT",+ "TN",+ "TR",+ "TM",+ "TV",+ "UG",+ "UA",+ "AE",+ "GB",+ "US",+ "UY",+ "UZ",+ "VU",+ "VA",+ "VE",+ "VN",+ "YE",+ "ZM",+ "ZW",+] as const;++type Language = (typeof languages)[number];+type Country = (typeof countries)[number];+type DateStyle = Intl.DateTimeFormatOptions["dateStyle"] | "none";+type TimeStyle = Intl.DateTimeFormatOptions["timeStyle"] | "none";++export type TimeProps = {+ datetime?: string;+ language?: Language;+ country?: Country;+ dateStyle?: DateStyle;+ timeStyle?: TimeStyle;+};++const INITIAL_DATE_STRING = "dateTime attribute is not set";+const INVALID_DATE_STRING = "";++const DEFAULT_LANGUAGE = "en";+const DEFAULT_COUNTRY = "GB";+const DEFAULT_DATE_STYLE = "medium";+const DEFAULT_TIME_STYLE = "none";++const languageOrDefault = (language: unknown): Language => {+ return languages.includes(language as Language)+ ? (language as Language)+ : DEFAULT_LANGUAGE;+};++const countryOrDefault = (country: unknown): Country => {+ return countries.includes(country as Country)+ ? (country as Country)+ : DEFAULT_COUNTRY;+};++const dateStyleOrUndefined = (+ value: unknown+): Intl.DateTimeFormatOptions["dateStyle"] => {+ if (["full", "long", "medium", "short"].includes(value as string)) {+ return value as Intl.DateTimeFormatOptions["dateStyle"];+ }+ return undefined;+};++const timeStyleOrUndefined = (+ value: unknown+): Intl.DateTimeFormatOptions["timeStyle"] => {+ if (["full", "long", "medium", "short"].includes(value as string)) {+ return value as Intl.DateTimeFormatOptions["timeStyle"];+ }+ return undefined;+};++export const Time = React.forwardRef<React.ElementRef<"time">, TimeProps>(+ (+ {+ language = DEFAULT_LANGUAGE,+ country = DEFAULT_COUNTRY,+ dateStyle = DEFAULT_DATE_STYLE,+ timeStyle = DEFAULT_TIME_STYLE,+ datetime = INITIAL_DATE_STRING,+ ...props+ },+ ref+ ) => {+ const locale = `${languageOrDefault(language)}-${countryOrDefault(+ country+ )}`;++ const options: Intl.DateTimeFormatOptions = {+ dateStyle: dateStyleOrUndefined(dateStyle),+ timeStyle: timeStyleOrUndefined(timeStyle),+ };++ const datetimeString =+ datetime === null ? INVALID_DATE_STRING : datetime.toString();++ const date = new Date(datetimeString);+ const isValidDate = false === Number.isNaN(date.getTime());++ let formattedDate = datetimeString;++ if (isValidDate) {+ try {+ formattedDate = new Intl.DateTimeFormat(locale, options).format(date);+ } catch {+ /* Do Nothing */+ }+ }++ return (+ <time ref={ref} dateTime={datetimeString} {...props}>+ {formattedDate}+ </time>+ );+ }+);diff --git a/packages/sdk-components-react/src/time.ws.ts b/packages/sdk-components-react/src/time.ws.tsnew file mode 100644index 0000000000..e7faa25343--- /dev/null+++ b/packages/sdk-components-react/src/time.ws.ts@@ -0,0 +1,32 @@+import { CalendarIcon } from "@webstudio-is/icons/svg";++import {+ defaultStates,+ type PresetStyle,+ type WsComponentMeta,+ type WsComponentPropsMeta,+} from "@webstudio-is/react-sdk";++import { time } from "@webstudio-is/react-sdk/css-normalize";++import { props } from "./__generated__/time.props";++const presetStyle = {+ time,+} satisfies PresetStyle<"time">;++export const meta: WsComponentMeta = {+ category: "data",+ type: "container",+ description:+ "Converts machine-readable date and time to a human-readable format.",+ icon: CalendarIcon,+ states: defaultStates,+ presetStyle,+ order: 4,+};++export const propsMeta: WsComponentPropsMeta = {+ props,+ initialProps: ["datetime", "language", "country", "dateStyle", "timeStyle"],+};