-
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.
Ajoute une estimation visible de la longueur des messages en nombre d…
…e segment SMS
- Loading branch information
Showing
7 changed files
with
90 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,45 @@ | ||
import { useState } from "react"; | ||
import { SegmentedMessage } from "sms-segments-calculator"; | ||
|
||
export function MessageInputControl({ value, onChange, onCtrlEnter }) { | ||
function SmsSegmentHelpText() { | ||
const v = new SegmentedMessage(value || ""); | ||
const maxBitsInSegment = 1120; // max size of a SMS is 140 octets -> 140 * 8bits = 1120 bits | ||
return ( | ||
<p className="help"> | ||
<div className="messageSegments"> | ||
{v.segments.map((segment) => ( | ||
<progress | ||
className="progress" | ||
value={segment.sizeInBits()} | ||
max={maxBitsInSegment} | ||
> | ||
{segment.sizeInBits()}/{maxBitsInSegment} | ||
</progress> | ||
))} | ||
</div> | ||
{v.segments.length > 1 | ||
? `Ce message sera réparti sur ${v.segments.length} segments SMS.` | ||
: ""} | ||
</p> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="control"> | ||
<textarea | ||
className="textarea" | ||
id="message" | ||
rows="5" | ||
value={value} | ||
onChange={onChange} | ||
onKeyUp={(e) => { | ||
if (e.ctrlKey && e.keyCode == 13 && onCtrlEnter) { | ||
onCtrlEnter(e); | ||
} | ||
}} | ||
/> | ||
<SmsSegmentHelpText /> | ||
</div> | ||
); | ||
} |
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