ds-one 0.3.0-alpha.6 → 0.3.0-alpha.7

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.
@@ -1,4 +1,4 @@
1
- /* version 0.3.0-alpha.6 */
1
+ /* version 0.3.0-alpha.7 */
2
2
 
3
3
  @import url("https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400&display=swap");
4
4
  @import url("https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@350&display=swap");
@@ -6,7 +6,14 @@ import styles from "./styles/ds-text.css?inline";
6
6
  * A component for displaying text from translations
7
7
  *
8
8
  * @element ds-text
9
- * @prop {string} text - The translation text to use
9
+ * @prop {string} text - The translation key (optional if using slot content)
10
+ *
11
+ * @example
12
+ * // Using slot content as the key (preferred)
13
+ * <ds-text>Welcome to the app</ds-text>
14
+ *
15
+ * // Using text attribute (still supported)
16
+ * <ds-text text="Welcome to the app"></ds-text>
10
17
  */
11
18
  export class Text extends LitElement {
12
19
  static get properties() {
@@ -19,6 +26,7 @@ export class Text extends LitElement {
19
26
  declare text: string;
20
27
  declare _text: string;
21
28
  declare _currentLanguage: string;
29
+ private _slotKey: string = "";
22
30
  private boundHandlers: { languageChanged: EventListener };
23
31
 
24
32
  constructor() {
@@ -30,7 +38,6 @@ export class Text extends LitElement {
30
38
  // Create bound event handlers for proper cleanup
31
39
  this.boundHandlers = {
32
40
  languageChanged: (() => {
33
- console.log("Language changed event received in ds-text");
34
41
  this._currentLanguage = currentLanguage.value;
35
42
  this._updateLanguageAttribute();
36
43
  this._loadText();
@@ -43,6 +50,17 @@ export class Text extends LitElement {
43
50
 
44
51
  connectedCallback() {
45
52
  super.connectedCallback();
53
+
54
+ // Capture slot content as the translation key if no text attribute
55
+ if (!this.text) {
56
+ const slotContent = this.textContent?.trim() || "";
57
+ if (slotContent) {
58
+ this._slotKey = slotContent;
59
+ // Clear the slot content - we'll render the translation in shadow DOM
60
+ this.textContent = "";
61
+ }
62
+ }
63
+
46
64
  this._currentLanguage = currentLanguage.value;
47
65
  this._updateLanguageAttribute();
48
66
  this._loadText();
@@ -58,9 +76,6 @@ export class Text extends LitElement {
58
76
  "translations-loaded",
59
77
  this.boundHandlers.languageChanged
60
78
  );
61
-
62
- // Listen for language changes via events instead of signals
63
- // The currentLanguage signal changes will trigger the language-changed event
64
79
  }
65
80
 
66
81
  disconnectedCallback() {
@@ -114,7 +129,10 @@ export class Text extends LitElement {
114
129
  }
115
130
 
116
131
  _loadText() {
117
- if (!this.text) {
132
+ // Use text attribute first, then slot content as fallback
133
+ const key = this.text || this._slotKey;
134
+
135
+ if (!key) {
118
136
  this._text = "";
119
137
  this._updateLanguageAttribute();
120
138
  this.requestUpdate();
@@ -122,18 +140,18 @@ export class Text extends LitElement {
122
140
  }
123
141
 
124
142
  try {
125
- const translatedText = getText(this.text);
126
- this._text = translatedText || this.text;
143
+ const translatedText = getText(key);
144
+ this._text = translatedText || key;
127
145
  } catch (error) {
128
- console.error("Error loading text for text:", this.text, error);
129
- this._text = this.text;
146
+ console.error("Error loading text for key:", key, error);
147
+ this._text = key;
130
148
  }
131
149
  this._updateLanguageAttribute();
132
150
  this.requestUpdate();
133
151
  }
134
152
 
135
153
  render() {
136
- return html`<span>${this._text || this.text}</span>`;
154
+ return html`<span>${this._text || this.text || this._slotKey}</span>`;
137
155
  }
138
156
  }
139
157
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # DS one (0.3.0-alpha.6)
1
+ # DS one (0.3.0-alpha.7)
2
2
 
3
3
  A plug and play design system
4
4
 
@@ -20,7 +20,7 @@ yarn add ds-one@alpha
20
20
 
21
21
  ```
22
22
 
23
- **Note**: Currently published as alpha version `0.3.0-alpha.6`
23
+ **Note**: Currently published as alpha version `0.3.0-alpha.7`
24
24
 
25
25
  ## Quick Start
26
26
 
@@ -3,7 +3,14 @@ import { LitElement } from "lit";
3
3
  * A component for displaying text from translations
4
4
  *
5
5
  * @element ds-text
6
- * @prop {string} text - The translation text to use
6
+ * @prop {string} text - The translation key (optional if using slot content)
7
+ *
8
+ * @example
9
+ * // Using slot content as the key (preferred)
10
+ * <ds-text>Welcome to the app</ds-text>
11
+ *
12
+ * // Using text attribute (still supported)
13
+ * <ds-text text="Welcome to the app"></ds-text>
7
14
  */
8
15
  export declare class Text extends LitElement {
9
16
  static get properties(): {
@@ -19,6 +26,7 @@ export declare class Text extends LitElement {
19
26
  text: string;
20
27
  _text: string;
21
28
  _currentLanguage: string;
29
+ private _slotKey;
22
30
  private boundHandlers;
23
31
  constructor();
24
32
  static styles: import("lit").CSSResult;
@@ -1 +1 @@
1
- {"version":3,"file":"ds-text.d.ts","sourceRoot":"","sources":["../../DS1/2-core/ds-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAIlD;;;;;GAKG;AACH,qBAAa,IAAK,SAAQ,UAAU;IAClC,MAAM,KAAK,UAAU;;;;;;;;;MAKpB;IAEO,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACjC,OAAO,CAAC,aAAa,CAAqC;;IAoB1D,MAAM,CAAC,MAAM,0BAAqB;IAElC,iBAAiB;IAsBjB,oBAAoB;IAYpB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAQ/C,wBAAwB;IA8BxB,SAAS;IAmBT,MAAM;CAGP;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,IAAI,CAAC;KACjB;CACF"}
1
+ {"version":3,"file":"ds-text.d.ts","sourceRoot":"","sources":["../../DS1/2-core/ds-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAIlD;;;;;;;;;;;;GAYG;AACH,qBAAa,IAAK,SAAQ,UAAU;IAClC,MAAM,KAAK,UAAU;;;;;;;;;MAKpB;IAEO,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,aAAa,CAAqC;;IAmB1D,MAAM,CAAC,MAAM,0BAAqB;IAElC,iBAAiB;IA8BjB,oBAAoB;IAYpB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAQ/C,wBAAwB;IA8BxB,SAAS;IAsBT,MAAM;CAGP;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,IAAI,CAAC;KACjB;CACF"}
@@ -5,7 +5,14 @@ import styles from "./styles/ds-text.css?inline";
5
5
  * A component for displaying text from translations
6
6
  *
7
7
  * @element ds-text
8
- * @prop {string} text - The translation text to use
8
+ * @prop {string} text - The translation key (optional if using slot content)
9
+ *
10
+ * @example
11
+ * // Using slot content as the key (preferred)
12
+ * <ds-text>Welcome to the app</ds-text>
13
+ *
14
+ * // Using text attribute (still supported)
15
+ * <ds-text text="Welcome to the app"></ds-text>
9
16
  */
10
17
  export class Text extends LitElement {
11
18
  static get properties() {
@@ -16,13 +23,13 @@ export class Text extends LitElement {
16
23
  }
17
24
  constructor() {
18
25
  super();
26
+ this._slotKey = "";
19
27
  this.text = "";
20
28
  this._text = "";
21
29
  this._currentLanguage = currentLanguage.value;
22
30
  // Create bound event handlers for proper cleanup
23
31
  this.boundHandlers = {
24
32
  languageChanged: (() => {
25
- console.log("Language changed event received in ds-text");
26
33
  this._currentLanguage = currentLanguage.value;
27
34
  this._updateLanguageAttribute();
28
35
  this._loadText();
@@ -32,6 +39,15 @@ export class Text extends LitElement {
32
39
  }
33
40
  connectedCallback() {
34
41
  super.connectedCallback();
42
+ // Capture slot content as the translation key if no text attribute
43
+ if (!this.text) {
44
+ const slotContent = this.textContent?.trim() || "";
45
+ if (slotContent) {
46
+ this._slotKey = slotContent;
47
+ // Clear the slot content - we'll render the translation in shadow DOM
48
+ this.textContent = "";
49
+ }
50
+ }
35
51
  this._currentLanguage = currentLanguage.value;
36
52
  this._updateLanguageAttribute();
37
53
  this._loadText();
@@ -39,8 +55,6 @@ export class Text extends LitElement {
39
55
  window.addEventListener("language-changed", this.boundHandlers.languageChanged);
40
56
  // Also listen for translations loaded event
41
57
  window.addEventListener("translations-loaded", this.boundHandlers.languageChanged);
42
- // Listen for language changes via events instead of signals
43
- // The currentLanguage signal changes will trigger the language-changed event
44
58
  }
45
59
  disconnectedCallback() {
46
60
  super.disconnectedCallback();
@@ -80,25 +94,27 @@ export class Text extends LitElement {
80
94
  this.removeAttribute("data-language");
81
95
  }
82
96
  _loadText() {
83
- if (!this.text) {
97
+ // Use text attribute first, then slot content as fallback
98
+ const key = this.text || this._slotKey;
99
+ if (!key) {
84
100
  this._text = "";
85
101
  this._updateLanguageAttribute();
86
102
  this.requestUpdate();
87
103
  return;
88
104
  }
89
105
  try {
90
- const translatedText = getText(this.text);
91
- this._text = translatedText || this.text;
106
+ const translatedText = getText(key);
107
+ this._text = translatedText || key;
92
108
  }
93
109
  catch (error) {
94
- console.error("Error loading text for text:", this.text, error);
95
- this._text = this.text;
110
+ console.error("Error loading text for key:", key, error);
111
+ this._text = key;
96
112
  }
97
113
  this._updateLanguageAttribute();
98
114
  this.requestUpdate();
99
115
  }
100
116
  render() {
101
- return html `<span>${this._text || this.text}</span>`;
117
+ return html `<span>${this._text || this.text || this._slotKey}</span>`;
102
118
  }
103
119
  }
104
120
  Text.styles = unsafeCSS(styles);
@@ -1927,20 +1927,14 @@ o$1?.({ LitElement: i2 });
1927
1927
  (s.litElementVersions ?? (s.litElementVersions = [])).push("4.2.1");
1928
1928
  const styles$f = '/* ds-text.css */\n/* Text component styles for displaying translations */\n\n:host {\n display: inline-flex;\n align-items: center;\n justify-content: flex-start;\n height: calc(16px * var(--sf));\n font-family: var(--typeface-regular);\n font-size: var(--type-size-default);\n font-weight: var(--type-weight-default);\n line-height: calc(var(--type-lineheight-default) * var(--sf));\n letter-spacing: calc(var(--type-letterspacing-default) * var(--sf));\n text-align: left;\n text-transform: var(--text-transform-default);\n text-decoration: var(--text-decoration-default);\n vertical-align: middle;\n white-space: nowrap;\n color: inherit;\n}\n\n:host([data-language="ja"]) {\n font-family: var(--typeface-regular-jp);\n}\n\n:host([data-language="zh"]),\n:host([data-language="zh-hant"]) {\n font-family: var(--typeface-regular-zh-hant);\n font-weight: 800;\n}\n\n:host([data-language="zh-hans"]) {\n font-family: var(--typeface-regular-zh-hans);\n font-weight: 800;\n}\n\n:host span {\n color: inherit;\n}\n';
1929
1929
  const _Text = class _Text extends i2 {
1930
- static get properties() {
1931
- return {
1932
- text: { type: String, reflect: true },
1933
- _text: { type: String, state: true }
1934
- };
1935
- }
1936
1930
  constructor() {
1937
1931
  super();
1932
+ this._slotKey = "";
1938
1933
  this.text = "";
1939
1934
  this._text = "";
1940
1935
  this._currentLanguage = currentLanguage.value;
1941
1936
  this.boundHandlers = {
1942
1937
  languageChanged: (() => {
1943
- console.log("Language changed event received in ds-text");
1944
1938
  this._currentLanguage = currentLanguage.value;
1945
1939
  this._updateLanguageAttribute();
1946
1940
  this._loadText();
@@ -1948,8 +1942,21 @@ const _Text = class _Text extends i2 {
1948
1942
  })
1949
1943
  };
1950
1944
  }
1945
+ static get properties() {
1946
+ return {
1947
+ text: { type: String, reflect: true },
1948
+ _text: { type: String, state: true }
1949
+ };
1950
+ }
1951
1951
  connectedCallback() {
1952
1952
  super.connectedCallback();
1953
+ if (!this.text) {
1954
+ const slotContent = this.textContent?.trim() || "";
1955
+ if (slotContent) {
1956
+ this._slotKey = slotContent;
1957
+ this.textContent = "";
1958
+ }
1959
+ }
1953
1960
  this._currentLanguage = currentLanguage.value;
1954
1961
  this._updateLanguageAttribute();
1955
1962
  this._loadText();
@@ -1998,24 +2005,25 @@ const _Text = class _Text extends i2 {
1998
2005
  this.removeAttribute("data-language");
1999
2006
  }
2000
2007
  _loadText() {
2001
- if (!this.text) {
2008
+ const key = this.text || this._slotKey;
2009
+ if (!key) {
2002
2010
  this._text = "";
2003
2011
  this._updateLanguageAttribute();
2004
2012
  this.requestUpdate();
2005
2013
  return;
2006
2014
  }
2007
2015
  try {
2008
- const translatedText = getText(this.text);
2009
- this._text = translatedText || this.text;
2016
+ const translatedText = getText(key);
2017
+ this._text = translatedText || key;
2010
2018
  } catch (error) {
2011
- console.error("Error loading text for text:", this.text, error);
2012
- this._text = this.text;
2019
+ console.error("Error loading text for key:", key, error);
2020
+ this._text = key;
2013
2021
  }
2014
2022
  this._updateLanguageAttribute();
2015
2023
  this.requestUpdate();
2016
2024
  }
2017
2025
  render() {
2018
- return x`<span>${this._text || this.text}</span>`;
2026
+ return x`<span>${this._text || this.text || this._slotKey}</span>`;
2019
2027
  }
2020
2028
  };
2021
2029
  _Text.styles = r$1(styles$f);