-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from Automattic/border
Block border
- Loading branch information
Showing
15 changed files
with
348 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
interface Attributes { | ||
defaultHomeserver?: string, | ||
roomId?: string, | ||
height: Height, | ||
borderWidth: BorderWidth, | ||
borderRadius: BorderRadius, | ||
borderStyle: string, | ||
borderColor: string, | ||
} | ||
|
||
export function parseAttributes(attributes): Attributes { | ||
return { | ||
defaultHomeserver: attributes.defaultHomeserver ?? '', | ||
roomId: attributes.roomId ?? '', | ||
height: new Height(attributes.height.value, attributes.height.unit), | ||
borderWidth: new BorderWidth(attributes.borderWidth.value, attributes.borderWidth.unit), | ||
borderRadius: new BorderRadius(attributes.borderRadius.value, attributes.borderRadius.unit), | ||
borderStyle: attributes.borderStyle, | ||
borderColor: attributes.borderColor, | ||
}; | ||
} | ||
|
||
export enum Unit { | ||
px = "px", | ||
} | ||
|
||
function unitFromString(value: string): Unit | undefined { | ||
switch (value) { | ||
case Unit.px: | ||
return Unit.px; | ||
} | ||
return undefined; | ||
} | ||
|
||
class ValueWithUnit { | ||
protected readonly value: number; | ||
protected readonly unit?: Unit; | ||
|
||
constructor(value: number, unit: Unit | string) { | ||
this.value = value; | ||
|
||
if (typeof unit === "string") { | ||
this.unit = unitFromString(unit); | ||
} else { | ||
this.unit = unit; | ||
} | ||
} | ||
|
||
public toString(): string { | ||
return this.value && this.unit ? `${this.value}${this.unit}` : ''; | ||
} | ||
} | ||
|
||
export class Height extends ValueWithUnit { | ||
constructor(value: number, unit: Unit | string) { | ||
super(value, unit); | ||
} | ||
} | ||
|
||
export class BorderWidth extends ValueWithUnit { | ||
constructor(value: number, unit: Unit | string) { | ||
super(value, unit); | ||
} | ||
|
||
public toString(): string { | ||
return this.value && this.unit ? `${this.value}${this.unit}` : '0'; | ||
} | ||
} | ||
|
||
export class BorderRadius extends ValueWithUnit { | ||
constructor(value: number, unit: Unit | string) { | ||
super(value, unit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { PanelBody, PanelRow, TextControl } from "@wordpress/components"; | ||
import { WPElement } from "@wordpress/element"; | ||
import { __ } from "@wordpress/i18n"; | ||
|
||
export default function HomeserverPanel({ attributes, setAttributes }): WPElement { | ||
return ( | ||
<PanelBody | ||
title={__("Homeserver", "chatrix")} | ||
initialOpen={true} | ||
> | ||
<PanelRow> | ||
<TextControl | ||
label={__("Default Homeserver", "chatrix")} | ||
value={attributes.defaultHomeserver} | ||
onChange={(value) => setAttributes({ defaultHomeserver: value })} | ||
/> | ||
</PanelRow> | ||
</PanelBody> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { InspectorControls as BaseInspectorControls } from "@wordpress/block-editor"; | ||
import { WPElement } from "@wordpress/element"; | ||
import HomeserverPanel from "./HomeserverPanel"; | ||
import RoomPanel from "./RoomPanel"; | ||
import StylePanel from "./StylePanel"; | ||
|
||
export default function InspectorControls({ attributes, setAttributes }): WPElement { | ||
return ( | ||
<BaseInspectorControls> | ||
<div className={"chatrix-inspector-controls"}> | ||
<HomeserverPanel attributes={attributes} setAttributes={setAttributes}/> | ||
<RoomPanel attributes={attributes} setAttributes={setAttributes}/> | ||
<StylePanel attributes={attributes} setAttributes={setAttributes}/> | ||
</div> | ||
</BaseInspectorControls> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { PanelBody, PanelRow, TextControl } from "@wordpress/components"; | ||
import { WPElement } from "@wordpress/element"; | ||
import { __ } from "@wordpress/i18n"; | ||
|
||
export default function RoomPanel({ attributes, setAttributes }): WPElement { | ||
return ( | ||
<PanelBody | ||
title={__("Room", "chatrix")} | ||
initialOpen={false} | ||
> | ||
<PanelRow> | ||
<TextControl | ||
label={__("Room id (optional)", "chatrix")} | ||
value={attributes.roomId} | ||
onChange={(value) => setAttributes({ roomId: value })} | ||
help={<RoomIdHelp/>} | ||
/> | ||
</PanelRow> | ||
</PanelBody> | ||
); | ||
} | ||
|
||
function RoomIdHelp() { | ||
return ( | ||
<> | ||
<span>{__("When a room id is specified, the client will be in single-room mode.", "chatrix")}</span><br/><br/> | ||
<span>{__("In this mode, the client opens directly in that room, with the user not having access to the screen that shows the list of rooms.", "chatrix")}</span><br/><br/> | ||
<span>{__("The room must be public, so that the user can join without requiring an invitation.", "chatrix")}</span><br/><br/> | ||
<span>{__("The room id must be the room's actual id, it must not be an alias.", "chatrix")}</span><br/><br/> | ||
<span>{__("Example: !abc123:example.com", "chatrix")}</span><br/> | ||
</> | ||
); | ||
} |
Oops, something went wrong.